Working with files

5. Working with files

In addition to performing common file manipulation tasks, such as moving, copying, and deleting, you'll also want to download files from the Internet, search for files in your directories, and FTP files. Some of these functions are built into Emacs, while some of these tasks require additional applications that can be downloaded.

5.1. Downloading files

Once you know the URL of the file to download, you can use the wget command from within the Emacs shell to retrieve the file. If you do not know the URL of the file to download, use the W3 application to browse the web and find the URL of the file (refer to Browsing the Internet for information on using the W3 application). Then use the command wget to download it. For more information on the wget command, refer to the wget man page.

To download a file:

  1. From inside Emacs, type M-x shell to start the shell.

  2. Since the wget command places the downloaded file into your current directory, change directories to the desired directory.

  3. When you are in the appropriate directory, type wget [url], then press Enter. Remember that you can copy and paste the URL of the file to download from the W3 web browser application.

As the file is being downloaded, one dot appears on the screen for each kilobyte of data received. The wget command lets you know when the download is complete.

Another option for downloading (or uploading) a file is via FTP. Refer to FTPing a file for more information.

5.4. Manipulating files

This section contains information on moving, copying, and deleting files from within Emacs. In general, there are two ways you can go about these tasks. One option is to use the command line from an Emacs shell, and the other is to use dired. Both methods are discussed in this section.

5.4.2. Using the directory editor

Although many Linux users use the command line to manipulate files, Emacs provides a powerful alternative, called dired. Dired is the Emacs directory editor, and is great for manipulating files if you'd rather not use the command line or aren't familiar with it. To start dired:

  1. In Emacs, type M-x dired. You will be prompted for the directory to open.

  2. Type in the directory to display, or press Return to open the default directory.

Once you've started dired, you can move around in the Emacs buffer to have the file names, permissions, owners, sizes, and dates created/edited read aloud.

In dired, some commands mark files for manipulation (for example, you can mark several files, then delete them all), and some commands (such as the copy command) are executed immediately. Note that, in dired, case does make a difference for many commands. Some of the more common dired commands and what they do are listed below:

Because dired is so extensive, including the full documentation for it here is not feasible. However, complete instructions can be found in the GNU Emacs Manual at http://www.delorie.com/gnu/docs/emacs/emacs_360.html.