Emacs asks you to confirm the deletion by typing yes(Windows).
Type yesto delete them all or type noto 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 yesto delete the file immediately or noto change your mind. In Dired, this is one of a number of cases in which the lowercase letter (like dto flag for deletion) and the uppercase letter (like Dto delete immediately) have a different meaning.
To copy a file in Dired, type Cnext 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 3Cwould 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 mvcommand), type Rnext 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 %lfor lowercase or %ufor uppercase. Voilà—painless case consistency.
5.2.3 Compressing and Uncompressing Files
Compressing files saves disk space, and Dired provides an easy way to do it. Put the cursor on the line of the file you want to compress and press Z(for dired-do-compress). Emacs asks the following:
Compress or uncompress filename ? (y or n)
Emacs compresses the file if it's not compressed and uncompresses it if it is. [28]Press yto compress or uncompress the current file. Compression happens immediately, so you can watch both the extension and file size change as Emacs compresses the file.
What about editing compressed files? Although it's not on by default, Emacs has an automatic compression/decompression mode called auto-compress mode. To enter it for this session, type M-x auto-compress-mode Enter, which turns automatic compression on. To enable auto-compression automatically, add this line to your .emacs file:
(auto-compression-mode 1)
In Chapter 4, we discussed comparing files in two windows. Emacs provides a way to do this using the diffcommand in Dired. Set the mark on the file you want diffto compare, put the cursor on the other file, then type =. Emacs compares the two files and opens a window with a *diff*
buffer containing the output from the command.
Emacs has a separate option for comparing a file to its backup file. Put the cursor on the file you want to compare with its backup and type M-=. Emacs displays a *diff*
buffer showing the differences between the two files.
If you are serious about version control, you may want to check out Chapter 12, which discusses version control as well as the GNU tool ediff.
5.2.5 Running Shell Commands on Files
While Dired's implementation of diffis useful (and there are implementations of chmod, grep, and findas well), in a more general sense, you can perform any command on a file by pressing an exclamation point ( !). For example, let's alphabetize the phone list file using the sortcommand.
Move to the phone file and press !

Emacs asks what command you want to run (Mac OS X).
Type: sort

Emacs displays the output from the command in a separate window (Mac OS X).
Usually, asterisks (*) and question marks are used as wildcards in commands. In Dired, they have a special meaning. An asterisk means "use the file I'm on or the files I've marked"; that way you don't have to type filenames explicitly. When multiple files are marked, a question mark means to run this command separately on each file.
In a slightly more complex example, you might have a command with more than one file as an argument. For example, you might want to make a new file out of the sorted phone list.
Move the cursor to the phone file, then type: !

Emacs asks what command you want to run (Mac OS X).
Now tell Emacs you want to sort your phone file and put the output in a new file called phonesorted . The cursor is on the phone file, so you don't need to type its name in the command. Substitute an asterisk (*) for the name of the file:
Type: sort * > phonesorted

The operating system sorts the phone file and puts the output into the new file phonesorted (Mac OS X).
We created the file, but it doesn't appear on the display, which is not automatically updated in this case. To see the phonesorted file, type g.
Type: g

Emacs updates the Dired display, showing the file phonesorted (Mac OS X).
Dired is frankly inconsistent about whether you type gbefore the display is updated. Some commands, as we'll see shortly, update the display immediately. Others, such as running shell commands on files, do not (Emacs really doesn't know what shell commands it's running or their effect on the display). A good rule of thumb is to type gif you don't see what you expect to see.
5.2.6 Working with Groups of Files
So far we've talked about working with one file at a time; any commands you give apply to the file the cursor is on. Working with multiple files is a better illustration of the real power of Dired. You can organize your directories in a flash once you learn a few shortcuts. First let's talk about some ways to select files, and then we'll talk about what we can do with the selected files.
So far we've primarily talked about flagging files for deletion. When you want to do something else with a group of files, you first mark them with an asterisk. Pressing mmarks the file the cursor is on; an asterisk appears where you normally see a D. Typing 3mmarks this file and the next two files. Once you mark files with an asterisk, Emacs assumes that any command you issue is meant for these files. So if you have three files marked with an asterisk and press Zto compress, Emacs assumes you want to compress those three files. After the compression, the files remain marked with asterisks. So how do you get rid of the asterisks when you're done with these files?
Читать дальше