To remove the asterisks, you press M-Del(for dired-unmark-all-files). Emacs asks which marks to remove. Press Enter, and Emacs removes all the marks.
Sometimes it's easier to mark the files you don't want to work with than those you do. Pressing ttoggles the marks, marking all unmarked files and removing marks from those previously marked.
5.2.6.2 Selecting likely candidates for deletion
Marking files sequentially is simple but, in all honesty, it's not very powerful. Emacs provides commands for selecting types of files that you often want to get rid of when you're cleaning up a directory: backup files, auto-save files, and so-called garbage files.
Auto-save files are created when a session terminates abnormally; they have the format # filename #
. Backup files which Emacs creates periodically, have the format filename ~
. To mark these files in Dired, type #or ~respectively.
Emacs also has an option that automatically selects "garbage" files. By default, this includes files with the following extensions: .log , .toc , .dvi , .bak , .orig , and .rej . Garbage files are defined by a regular expression, which is contained in the variable dired-garbage-files-regexp; you can change the value of this variable to define garbage files as you see fit (after all, one man's junk is another man's treasure).
5.2.6.3 Selecting files by type
Dired provides commands for selecting executable files, directories, and symbolic links. To select executable files, type * *. To select directories, type * /. Typing * @marks symbolic links.
5.2.6.4 Using regular expressions to choose files
Often you want to select related files and either archive them, move them, compress them, or just delete them. Typically, you use wildcards to select multiple files. In Dired, you use regular expressions. To mark a group of files whose filenames match a regular expression, press %followed by mto mark them with an asterisk.
For example, let's mark all the files that start with ch . Remembering the quick lesson on regular expressions from Chapter 3 Chapter 3. Search and Replace The commands we discussed in the first two chapters are enough to get you started, but they're certainly not enough to do any serious editing. If you're using Emacs for anything longer than a few paragraphs, you'll want the support this chapter describes. In this chapter, we cover the various ways that Emacs lets you search for and replace text. Emacs provides the traditional search and replace facilities you would expect in any editor; it also provides several important variants, including incremental searches, regular expression searches, and query-replace. We also cover spell-checking here, because it is a type of replacement (errors are sought and replaced with corrections). Finally, we cover word abbreviation mode; this feature is a type of automatic replacement that can be a real timesaver.
, ^finds the beginning of a word, so the regular expression ^chwould mark all the files that start with ch .
Type: %m

Emacs asks for a regular expression so that it can mark the files (Windows).
Type: ^ch Enter

Emacs marks all the files starting with ch and tells you how many it marked.
Sometimes it's more useful to mark files whose contents match a given regular expression. To mark files that contain a certain regular expression, type % g, followed by the regular expression to match (think g for grep if you're familiar with grep ).
Now that we've got the files marked, let's talk about what to do with them.
5.2.6.5 Operating on groups of files
In the course of daily work, a directory can get cluttered with many different kinds of files. Eventually, you need to make subdirectories to organize the files by project, then move the files to those subdirectories. You can do both these things from within Dired.
Let's say that the ch files are chapters from a novel you work on in your spare time. We need a subdirectory called novel to store the files in. You can create a directory by typing +(for dired-create-directory).
Type: +

Emacs asks for a directory name (Windows).
Type: novel Enter

Emacs creates the directory and displays it on the screen (Windows).
Now let's move the ch files we marked into the new directory. We'll use the rename command, R. This command, like the Unix mvcommand, is used for renaming files and for moving them. Because we have marked more than one file with an asterisk, when we type R, Emacs assumes we mean to move the marked files.
Type: R

Emacs asks where you want to move the marked files to (Windows).
Type: novel Enter

Emacs moves the files (Windows).
Now you can see that the files have moved. Marking files by regular expression allows you to work with a select group of files quickly.
One of the more interesting things you can do with a group of files is perform a query-replace on all of them with a single command. On large projects, a last-minute change often forces arduous searching and replacing of certain text in each file. First, select the files you want to include in the query-replace, then press Q(for dired-do-query-replace). Put in the search string, then the replacement string (the strings can be plain text or a regular expression) and Emacs starts a query-replace that moves you through each file sequentially. Here's the only hitch: if you interrupt the query-replace with a recursive edit, you can't restart it without going back to the Dired buffer.
Another interesting command is searching across files for a given regular expression. To do this, mark the files, then press A. Emacs stops at the first match; press M-, to move to the next match.
5.2.7 Navigating Directories
Often when you are cleaning up directories, you're moving files between them, organizing subdirectories, and the like. This naturally involves a lot of moving among directories.
To move to the parent directory of the one you're in, press ^. To move to the next directory in the buffer, press >; pressing <, not surprisingly, moves you to the previous directory in the buffer.
Читать дальше