Sending Files by E-mail

March 1st, 2000 by Marjorie Richardson in

When it's time to send those source files to your project leader, Linux has the commands you need.
Your rating: None Average: 5 (1 vote)

Often, we have files we wish to send colleagues and friends by e-mail. Depending on the type of file you wish to send, there is a Linux command to make the process easy for you.

Plaintext Files

The shell archive file command shar is very useful for combining plaintext files into one file, which can then be sent by e-mail. shar writes shell commands for unpacking the output file inside the file itself, as well as code to verify the content using an MD5 checksum. It is much easier to use than the archive command tar, whose complexities can trip up even an expert. All you have to do to run shar is type:

shar input_filenames > filename.shar

It will take all the input files and write them to the output file, embedding the unpacking commands as it goes. The extension conventionally used with shar output files is .shar. To unpack the file, you don't need to know the embedded commands or retrieve them from the file yourself. Instead, use the command sh. The first argument to uuencode is the input file name; the second is the name to put in the output file header. We will use the same name for both. Type:

sh filename.shar
The sh command will do the work for you by reading the file, extracting the commands and executing them to unpack the archive.

It is permissible to use wild cards in naming your shar input files, so you can easily pack all the files in one or more directories. Just remember, the files must all be plaintext—no binaries.

The purpose of the shar command is quite similar to that of tar. However, the command and its format are much easier to remember, and since the output is plaintext instead of binary, it does not need to be encoded to send it as e-mail.

Binaries and Graphics

Non-plaintext files such as binaries and graphics must be encoded before e-mailing them. First, pack and compress your files using tar, which outputs a binary file. We won't go into tar in detail here, since it has been discussed before: see “Tar and Taper for Linux” by Yusuf Nagree, Linux Journal, February 1996 (http://www.linuxjournal.com/lj-issues/issue22/1216.html). A simple command to pack and compress all the files in the current directory would look like this:

tar -cvzf tar_files.tgz *

Now, the tar file can be encoded using the command uuencode by typing:

uuencode tar_file.tgz tar_file.tgz > mail_file
The output file can now be put into e-mail and sent off into the ether.

The recipient can save the e-mail (perhaps as mail.save) and decode the file easily—no need to even remove mail headers. Simply use the command uudecode by typing:

uudecode mail.save

uudecode will do just what its name says: decode the mail file, leaving a file called tar_file.tgz in the current directory. To unpack the tar file, type:

tar -xvzf tar_file.tgz
A single graphics file can be encoded and decoded in the same way, skipping the tar step since an archive file is not needed.

Conclusion

No matter what type of files you have, sending them to others is not a chore using these simple Linux commands.

Marjorie Richardson is Editor in Chief of Linux Journal. She has been a programmer for many years and enjoys her role as Linux advocate very much.

__________________________


Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Post new comment

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Newsletter

Each week Linux Journal editors will tell you what's hot in the world of Linux. You will receive late breaking news, technical tips and tricks, and links to in-depth stories featured on www.linuxjournal.com.
Sign up for our Email Newsletter

Tech Tip Videos

From the Magazine

December 2009, #188

If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.


Read this issue