: Learning GNU Emacs, 3rd Edition

5.2.2 Deleting, Copying, and Renaming Files

5.2.2 Deleting, Copying, and Renaming Files

As we've said, file deletion is almost identical to buffer deletion with the buffer list. If you learned how to delete buffers, you know the basics of deleting files with Dired. First, you flag a file for deletion by moving to the file's name and typing d. Doing this places a D on the left margin and moves the cursor to the next file in the list. You can flag as many files as you want. You can change your mind at this point and type u to undelete the file. At some later time, you type x to delete the files (more on this in a minute). The following screen shows what the Dired buffer looks like when you flag a few files for deletion.

Type: d d d

Three files flagged for deletion (Windows).

As we mentioned, you can type u at any time to remove the deletion flags from the files. Typing u moves you to the next file in the list, and, if it is marked, unmarks it. You can also use Del to unmark. This command undeletes the previous file in the list and then moves up one line.

Because Emacs generates backup files and, at times, auto-save files, you may want to delete them from time to time. Emacs offers shortcut commands to flag such files. Typing # flags all the auto-save files (files whose names start and end with #) for deletion. Emacs flags them with D. Typing ~ flags all the backup files (whose names end with ~) for deletion. You can remove the flags from backup files you want to keep, for example, the backup copies of files you've recently worked on.

When you really want files to be deleted from disk, press x. Emacs displays the names of all the files flagged for deletion and asks you if you want to delete them.

Type: x

Emacs asks you to confirm the deletion by typing yes (Windows).

Type yes to delete them all or type no to return to the Dired buffer without deleting any of them.

This is the usual way of deleting files, but if you want a file deleted right away, type an uppercase D. Emacs asks if you want to delete the file (yes or no). Type yes to delete the file immediately or no to change your mind. In Dired, this is one of a number of cases in which the lowercase letter (like d to flag for deletion) and the uppercase letter (like D to delete immediately) have a different meaning.

To copy a file in Dired, type C next to it (it must be a capital C). Emacs asks for the name of the file you want to copy to. Type the name and press Enter. Emacs says, Copied: 1 file. To copy several files in the list, preface the C with a number. For example, typing 3C would copy this file and the next two files. (See "Working with Groups of Files" later in this chapter for fancier ways to select a group of files to operate on.)

To rename a file with Dired (similar to the Unix mv command), type R next to the filename. Emacs asks what the new name should be. Type it and press Enter. Emacs says, Moved: 1 file.

If you move files between platforms, you can wind up with some filenames in uppercase and some in lowercase. Files moving from older versions of Windows may be in all caps, for example. Simply mark the files in question by typing m, then press %l for lowercase or %u for uppercase. Voil?painless case consistency.

: 0.338. /Cache: 3 / 1