[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB. Dired, the Directory Editor

Dired makes an Emacs buffer containing a listing of a directory, and optionally some of its subdirectories as well. You can use the normal Emacs commands to move around in this buffer, and special Dired commands to operate on the files listed.

The Dired buffer is "read-only," and inserting text in it is not useful, so ordinary printing characters such as d and x are used for special Dired commands. Some Dired commands mark or flag the current file (that is, the file on the current line); other commands operate on the marked files or on the flagged files.

The Dired-X package provides various extra features for Dired mode. See section `Top' in Dired Extra Version 2 User's Manual.

AB.1 Entering Dired  How to invoke Dired.
AB.2 Navigation in the Dired Buffer  Special motion commands in the Dired buffer.
AB.3 Deleting Files with Dired  Deleting files with Dired.
AB.4 Flagging Many Files at Once  Flagging files based on their names.
AB.5 Visiting Files in Dired  Other file operations through Dired.
AB.6 Dired Marks vs. Flags  Flagging for deletion vs marking.
AB.7 Operating on Files  How to copy, rename, print, compress, etc. either one file or several files.
AB.8 Shell Commands in Dired  Running a shell command on the marked files.
AB.9 Transforming File Names in Dired  Using patterns to rename multiple files.
AB.10 File Comparison with Dired  Running `diff' by way of Dired.
AB.11 Subdirectories in Dired  Adding subdirectories to the Dired buffer.
AB.12 Moving Over Subdirectories  Moving across subdirectories, and up and down.
AB.13 Hiding Subdirectories  Making subdirectories visible or invisible.
AB.14 Updating the Dired Buffer  Discarding lines for files of no interest.
AB.15 Dired and find  Using `find' to choose the files for Dired.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.1 Entering Dired

To invoke Dired, do C-x d or M-x dired. The command reads a directory name or wildcard file name pattern as a minibuffer argument to specify which files to list. Where dired differs from list-directory is in putting the buffer into Dired mode so that the special commands of Dired are available.

The variable dired-listing-switches specifies the options to give to ls for listing directory; this string must contain `-l'. If you use a numeric prefix argument with the dired command, you can specify the ls switches with the minibuffer before you enter the directory specification.

To display the Dired buffer in another window rather than in the selected window, use C-x 4 d (dired-other-window) instead of C-x d. C-x 5 d (dired-other-frame) uses a separate frame to display the Dired buffer.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.2 Navigation in the Dired Buffer

All the usual Emacs cursor motion commands are available in Dired buffers. Some special-purpose cursor motion commands are also provided. The keys C-n and C-p are redefined to put the cursor at the beginning of the file name on the line, rather than at the beginning of the line.

For extra convenience, SPC and n in Dired are equivalent to C-n. p is equivalent to C-p. (Moving by lines is so common in Dired that it deserves to be easy to type.) DEL (move up and unflag) is often useful simply for moving up.

Some additional navigation commands are available when the Dired buffer includes several directories. See section AB.12 Moving Over Subdirectories.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.3 Deleting Files with Dired

One of the most frequent uses of Dired is to first flag files for deletion, then delete the files that were flagged.

d
Flag this file for deletion.
u
Remove deletion flag on this line.
DEL
Move point to previous line and remove the deletion flag on that line.
x
Delete the files that are flagged for deletion.

You can flag a file for deletion by moving to the line describing the file and typing d (dired-flag-file-deletion). The deletion flag is visible as a `D' at the beginning of the line. This command moves point to the next line, so that repeated d commands flag successive files. A numeric argument serves as a repeat count.

The variable dired-recursive-deletes controls whether the delete command will delete non-empty directories (including their contents). The default is to delete only empty directories.

The files are flagged for deletion rather than deleted immediately to reduce the danger of deleting a file accidentally. Until you direct Dired to delete the flagged files, you can remove deletion flags using the commands u and DEL. u (dired-unmark) works just like d, but removes flags rather than making flags. DEL (dired-unmark-backward) moves upward, removing flags; it is like u with argument -1.

To delete the flagged files, type x (dired-do-flagged-delete). (This is also known as expunging.) This command first displays a list of all the file names flagged for deletion, and requests confirmation with yes. If you confirm, Dired deletes the flagged files, then deletes their lines from the text of the Dired buffer. The shortened Dired buffer remains selected.

If you answer no or quit with C-g when asked to confirm, you return immediately to Dired, with the deletion flags still present in the buffer, and no files actually deleted.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.4 Flagging Many Files at Once

#
Flag all auto-save files (files whose names start and end with `#') for deletion (see section M.5 Auto-Saving: Protection Against Disasters).

~
Flag all backup files (files whose names end with `~') for deletion (see section M.3.1 Backup Files).

&
Flag for deletion all files with certain kinds of names, names that suggest you could easily create the files again.

. (Period)
Flag excess numeric backup files for deletion. The oldest and newest few backup files of any one file are exempt; the middle ones are flagged.

% d regexp RET
Flag for deletion all files whose names match the regular expression regexp.

The #, ~, &, and . commands flag many files for deletion, based on their file names. These commands are useful precisely because they do not themselves delete any files; you can remove the deletion flags from any flagged files that you really wish to keep.

& (dired-flag-garbage-files) flags files whose names match the regular expression specified by the variable dired-garbage-files-regexp. By default, this matches certain files produced by TeX, `.bak' files, and the `.orig' and `.rej' files produced by patch.

# (dired-flag-auto-save-files) flags for deletion all files whose names look like auto-save files (see section M.5 Auto-Saving: Protection Against Disasters)---that is, files whose names begin and end with `#'.

~ (dired-flag-backup-files) flags for deletion all files whose names say they are backup files (see section M.3.1 Backup Files)---that is, files whose names end in `~'.

. (period, dired-clean-directory) flags just some of the backup files for deletion: all but the oldest few and newest few backups of any one file. Normally dired-kept-versions (not kept-new-versions; that applies only when saving) specifies the number of newest versions of each file to keep, and kept-old-versions specifies the number of oldest versions to keep.

Period with a positive numeric argument, as in C-u 3 ., specifies the number of newest versions to keep, overriding dired-kept-versions. A negative numeric argument overrides kept-old-versions, using minus the value of the argument to specify the number of oldest versions of each file to keep.

The % d command flags all files whose names match a specified regular expression (dired-flag-files-regexp). Only the non-directory part of the file name is used in matching. You can use `^' and `$' to anchor matches. You can exclude subdirectories by hiding them (see section AB.13 Hiding Subdirectories).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.5 Visiting Files in Dired

There are several Dired commands for visiting or examining the files listed in the Dired buffer. All of them apply to the current line's file; if that file is really a directory, these commands invoke Dired on that subdirectory (making a separate Dired buffer).

f
Visit the file described on the current line, like typing C-x C-f and supplying that file name (dired-find-file). See section M.2 Visiting Files.

RET
e
Equivalent to f.

a
Like f, but replaces the contents of the Dired buffer with that of an alternate file or directory (dired-find-alternate-file).

o
Like f, but uses another window to display the file's buffer (dired-find-file-other-window). The Dired buffer remains visible in the first window. This is like using C-x 4 C-f to visit the file. See section O. Multiple Windows.

C-o
Visit the file described on the current line, and display the buffer in another window, but do not select that window (dired-display-file).

Mouse-2
Visit the file named by the line you click on (dired-mouse-find-file-other-window). This uses another window to display the file, like the o command.

v
View the file described on the current line, using M-x view-file (dired-view-file).

Viewing a file is like visiting it, but is slanted toward moving around in the file conveniently and does not allow changing the file. See section Miscellaneous File Operations.

^
Visit the parent directory of the current directory (dired-up-directory). This is more convenient than moving to the parent directory's line and typing f there.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.6 Dired Marks vs. Flags

Instead of flagging a file with `D', you can mark the file with some other character (usually `*'). Most Dired commands to operate on files use the files marked with `*', the exception being x which deletes the flagged files.

Here are some commands for marking with `*', or for unmarking or operating on marks. (See section AB.3 Deleting Files with Dired, for commands to flag and unflag files.)

m
* m
Mark the current file with `*' (dired-mark). With a numeric argument n, mark the next n files starting with the current file. (If n is negative, mark the previous -n files.)

* *
Mark all executable files with `*' (dired-mark-executables). With a numeric argument, unmark all those files.

* @
Mark all symbolic links with `*' (dired-mark-symlinks). With a numeric argument, unmark all those files.

* /
Mark with `*' all files which are actually directories, except for `.' and `..' (dired-mark-directories). With a numeric argument, unmark all those files.

* s
Mark all the files in the current subdirectory, aside from `.' and `..' (dired-mark-subdir-files).

u
* u
Remove any mark on this line (dired-unmark).

DEL
* DEL
Move point to previous line and remove any mark on that line (dired-unmark-backward).

* !
Remove all marks from all the files in this Dired buffer (dired-unmark-all-marks).

* ? markchar
Remove all marks that use the character markchar (dired-unmark-all-files). The argument is a single character--do not use RET to terminate it. See the description of the * c command below, which lets you replace one mark character with another.

With a numeric argument, this command queries about each marked file, asking whether to remove its mark. You can answer y meaning yes, n meaning no, or ! to remove the marks from the remaining files without asking about them.

* C-n
Move down to the next marked file (dired-next-marked-file) A file is "marked" if it has any kind of mark.

* C-p
Move up to the previous marked file (dired-prev-marked-file)

* t
Toggle all marks (dired-do-toggle): files marked with `*' become unmarked, and unmarked files are marked with `*'. Files marked in any other way are not affected.

* c old-markchar new-markchar
Replace all marks that use the character old-markchar with marks that use the character new-markchar (dired-change-marks). This command is the primary way to create or use marks other than `*' or `D'. The arguments are single characters--do not use RET to terminate them.

You can use almost any character as a mark character by means of this command, to distinguish various classes of files. If old-markchar is a space (` '), then the command operates on all unmarked files; if new-markchar is a space, then the command unmarks the files it acts on.

To illustrate the power of this command, here is how to put `D' flags on all the files that have no marks, while unflagging all those that already have `D' flags:

 
* c D t  * c SPC D  * c t SPC

This assumes that no files were already marked with `t'.

% m regexp RET
* % regexp RET
Mark (with `*') all files whose names match the regular expression regexp (dired-mark-files-regexp). This command is like % d, except that it marks files with `*' instead of flagging with `D'. See section AB.4 Flagging Many Files at Once.

Only the non-directory part of the file name is used in matching. Use `^' and `$' to anchor matches. Exclude subdirectories by hiding them (see section AB.13 Hiding Subdirectories).

% g regexp RET
Mark (with `*') all files whose contents contain a match for the regular expression regexp (dired-mark-files-containing-regexp). This command is like % m, except that it searches the file contents instead of the file name.

C-_
Undo changes in the Dired buffer, such as adding or removing marks (dired-undo). This command does not revert the actual file operations, nor recover lost files! It just undoes changes in the buffer itself. For example, if used after renaming one or more files, dired-undo restores the original names, which will get the Dired buffer out of sync with the actual contents of the directory.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.7 Operating on Files

This section describes the basic Dired commands to operate on one file or several files. All of these commands are capital letters; all of them use the minibuffer, either to read an argument or to ask for confirmation, before they act. All of them give you several ways to specify which files to manipulate:

Commands which ask for a destination directory, such as those which copy and rename files or create links for them, try to guess the default target directory for the operation. Normally, they suggest the Dired buffer's default directory, but if the variable dired-dwim-target is non-nil, and if there is another Dired buffer displayed in the next window, that other buffer's directory is suggested instead.

Here are the file-manipulating commands that operate on files in this way. (Some other Dired commands, such as ! and the `%' commands, also use these conventions to decide which files to work on.)

C new RET
Copy the specified files (dired-do-copy). The argument new is the directory to copy into, or (if copying a single file) the new name.

If dired-copy-preserve-time is non-nil, then copying with this command sets the modification time of the new file to be the same as that of the old file.

The variable dired-recursive-copies controls whether directories are copied recursively. The default is to not copy recursively, which means that directories cannot be copied.

D
Delete the specified files (dired-do-delete). Like the other commands in this section, this command operates on the marked files, or the next n files. By contrast, x (dired-do-flagged-delete) deletes all flagged files.

R new RET
Rename the specified files (dired-do-rename). The argument new is the directory to rename into, or (if renaming a single file) the new name.

Dired automatically changes the visited file name of buffers associated with renamed files so that they refer to the new names.

H new RET
Make hard links to the specified files (dired-do-hardlink). The argument new is the directory to make the links in, or (if making just one link) the name to give the link.

S new RET
Make symbolic links to the specified files (dired-do-symlink). The argument new is the directory to make the links in, or (if making just one link) the name to give the link.

M modespec RET
Change the mode (also called "permission bits") of the specified files (dired-do-chmod). This uses the chmod program, so modespec can be any argument that chmod can handle.

G newgroup RET
Change the group of the specified files to newgroup (dired-do-chgrp).

O newowner RET
Change the owner of the specified files to newowner (dired-do-chown). (On most systems, only the superuser can do this.)

The variable dired-chown-program specifies the name of the program to use to do the work (different systems put chown in different places).

P command RET
Print the specified files (dired-do-print). You must specify the command to print them with, but the minibuffer starts out with a suitable guess made using the variables lpr-command and lpr-switches (the same variables that lpr-buffer uses; see section AC.18 Hardcopy Output).

Z
Compress the specified files (dired-do-compress). If the file appears to be a compressed file already, it is uncompressed instead.

L
Load the specified Emacs Lisp files (dired-do-load). See section V.7 Libraries of Lisp Code for Emacs.

B
Byte compile the specified Emacs Lisp files (dired-do-byte-compile). See section `Byte Compilation' in The Emacs Lisp Reference Manual.

A regexp RET
Search all the specified files for the regular expression regexp (dired-do-search).

This command is a variant of tags-search. The search stops at the first match it finds; use M-, to resume the search and find the next match. See section W.2.6 Searching and Replacing with Tags Tables.

Q regexp RET to RET
Perform query-replace-regexp on each of the specified files, replacing matches for regexp with the string to (dired-do-query-replace-regexp).

This command is a variant of tags-query-replace. If you exit the query replace loop, you can use M-, to resume the scan and replace more matches. See section W.2.6 Searching and Replacing with Tags Tables.

One special file-operation command is + (dired-create-directory). This command reads a directory name and creates the directory if it does not already exist.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.8 Shell Commands in Dired

The Dired command ! (dired-do-shell-command) reads a shell command string in the minibuffer and runs that shell command on all the specified files. X is a synonym for !. You can specify the files to operate on in the usual ways for Dired commands (see section AB.7 Operating on Files). There are two ways of applying a shell command to multiple files:

What if you want to run the shell command once for each file, with the file name inserted in the middle? You can use `?' in the command instead of `*'. The current file name is substituted for `?'. You can use `?' more than once. For instance, here is how to uuencode each file, making the output file name by appending `.uu' to the input file name:

 
uuencode ? ? > ?.uu

To use the file names in a more complicated fashion, you can use a shell loop. For example, this shell command is another way to uuencode each file:

 
for file in *; do uuencode "$file" "$file" >"$file".uu; done

The working directory for the shell command is the top-level directory of the Dired buffer.

The ! command does not attempt to update the Dired buffer to show new or modified files, because it doesn't really understand shell commands, and does not know what files the shell command changed. Use the g command to update the Dired buffer (see section AB.14 Updating the Dired Buffer).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.9 Transforming File Names in Dired

This section describes Dired commands which alter file names in a systematic way.

Like the basic Dired file-manipulation commands (see section AB.7 Operating on Files), the commands described here operate either on the next n files, or on all files marked with `*', or on the current file. (To mark files, use the commands described in AB.6 Dired Marks vs. Flags.)

All of the commands described in this section work interactively: they ask you to confirm the operation for each candidate file. Thus, you can select more files than you actually need to operate on (e.g., with a regexp that matches many files), and then refine the selection by typing y or n when the command prompts for confirmation.

% u
Rename each of the selected files to an upper-case name (dired-upcase). If the old file names are `Foo' and `bar', the new names are `FOO' and `BAR'.

% l
Rename each of the selected files to a lower-case name (dired-downcase). If the old file names are `Foo' and `bar', the new names are `foo' and `bar'.

% R from RET to RET
% C from RET to RET
% H from RET to RET
% S from RET to RET
These four commands rename, copy, make hard links and make soft links, in each case computing the new name by regular-expression substitution from the name of the old file.

The four regular-expression substitution commands effectively perform a search-and-replace on the selected file names in the Dired buffer. They read two arguments: a regular expression from, and a substitution pattern to.

The commands match each "old" file name against the regular expression from, and then replace the matching part with to. You can use `\&' and `\digit' in to to refer to all or part of what the pattern matched in the old file name, as in replace-regexp (see section K.7.2 Regexp Replacement). If the regular expression matches more than once in a file name, only the first match is replaced.

For example, % R ^.*$ RET x-\& RET renames each selected file by prepending `x-' to its name. The inverse of this, removing `x-' from the front of each file name, is also possible: one method is % R ^x-\(.*\)$ RET \1 RET; another is % R ^x- RET RET. (Use `^' and `$' to anchor matches that should span the whole filename.)

Normally, the replacement process does not consider the files' directory names; it operates on the file name within the directory. If you specify a numeric argument of zero, then replacement affects the entire absolute file name including directory name. (Non-zero argument specifies the number of files to operate on.)

Often you will want to select the set of files to operate on using the same regexp that you will use to operate on them. To do this, mark those files with % m regexp RET, then use the same regular expression in the command to operate on the files. To make this easier, the % commands to operate on files use the last regular expression specified in any % command as a default.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.10 File Comparison with Dired

Here are two Dired commands that compare specified files using diff.

=
Compare the current file (the file at point) with another file (the file at the mark) using the diff program (dired-diff). The file at the mark is the first argument of diff, and the file at point is the second argument. Use C-SPC (set-mark-command) to set the mark at the first file's line (see section H.1 Setting the Mark), since dired-diff ignores the files marked with the Dired's m command.

M-=
Compare the current file with its latest backup file (dired-backup-diff). If the current file is itself a backup, compare it with the file it is a backup of; this way, you can compare a file with any backup version of your choice.

The backup file is the first file given to diff.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.11 Subdirectories in Dired

A Dired buffer displays just one directory in the normal case; but you can optionally include its subdirectories as well.

The simplest way to include multiple directories in one Dired buffer is to specify the options `-lR' for running ls. (If you give a numeric argument when you run Dired, then you can specify these options in the minibuffer.) That produces a recursive directory listing showing all subdirectories at all levels.

But usually all the subdirectories are too many; usually you will prefer to include specific subdirectories only. You can do this with the i command:

i
Insert the contents of a subdirectory later in the buffer.

Use the i (dired-maybe-insert-subdir) command on a line that describes a file which is a directory. It inserts the contents of that directory into the same Dired buffer, and moves there. Inserted subdirectory contents follow the top-level directory of the Dired buffer, just as they do in `ls -lR' output.

If the subdirectory's contents are already present in the buffer, the i command just moves to it.

In either case, i sets the Emacs mark before moving, so C-u C-SPC takes you back to the old position in the buffer (the line describing that subdirectory).

Use the l command (dired-do-redisplay) to update the subdirectory's contents. Use C-u k on the subdirectory header line to delete the subdirectory. See section AB.14 Updating the Dired Buffer.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.12 Moving Over Subdirectories

When a Dired buffer lists subdirectories, you can use the page motion commands C-x [ and C-x ] to move by entire directories (see section T.4 Pages).

The following commands move across, up and down in the tree of directories within one Dired buffer. They move to directory header lines, which are the lines that give a directory's name, at the beginning of the directory's contents.

C-M-n
Go to next subdirectory header line, regardless of level (dired-next-subdir).

C-M-p
Go to previous subdirectory header line, regardless of level (dired-prev-subdir).

C-M-u
Go up to the parent directory's header line (dired-tree-up).

C-M-d
Go down in the directory tree, to the first subdirectory's header line (dired-tree-down).

<
Move up to the previous directory-file line (dired-prev-dirline). These lines are the ones that describe a directory as a file in its parent directory.

>
Move down to the next directory-file line (dired-prev-dirline).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.13 Hiding Subdirectories

Hiding a subdirectory means to make it invisible, except for its header line, via selective display (see section J.9 Selective Display).

$
Hide or reveal the subdirectory that point is in, and move point to the next subdirectory (dired-hide-subdir). A numeric argument serves as a repeat count.

M-$
Hide all subdirectories in this Dired buffer, leaving only their header lines (dired-hide-all). Or, if any subdirectory is currently hidden, make all subdirectories visible again. You can use this command to get an overview in very deep directory trees or to move quickly to subdirectories far away.

Ordinary Dired commands never consider files inside a hidden subdirectory. For example, the commands to operate on marked files ignore files in hidden directories even if they are marked. Thus you can use hiding to temporarily exclude subdirectories from operations without having to remove the markers.

The subdirectory hiding commands toggle; that is, they hide what was visible, and show what was hidden.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.14 Updating the Dired Buffer

This section describes commands to update the Dired buffer to reflect outside (non-Dired) changes in the directories and files, and to delete part of the Dired buffer.

g
Update the entire contents of the Dired buffer (revert-buffer).

l
Update the specified files (dired-do-redisplay).

k
Delete the specified file lines---not the files, just the lines (dired-do-kill-lines).

s
Toggle between alphabetical order and date/time order (dired-sort-toggle-or-edit).

C-u s switches RET
Refresh the Dired buffer using switches as dired-listing-switches.

Type g (revert-buffer) to update the contents of the Dired buffer, based on changes in the files and directories listed. This preserves all marks except for those on files that have vanished. Hidden subdirectories are updated but remain hidden.

To update only some of the files, type l (dired-do-redisplay). Like the Dired file-operating commands, this command operates on the next n files (or previous -n files), or on the marked files if any, or on the current file. Updating the files means reading their current status, then updating their lines in the buffer to indicate that status.

If you use l on a subdirectory header line, it updates the contents of the corresponding subdirectory.

To delete the specified file lines from the buffer--not delete the files--type k (dired-do-kill-lines). Like the file-operating commands, this command operates on the next n files, or on the marked files if any; but it does not operate on the current file as a last resort.

If you kill the line for a file that is a directory, the directory's contents are also deleted from the buffer. Typing C-u k on the header line for a subdirectory is another way to delete a subdirectory from the Dired buffer.

The g command brings back any individual lines that you have killed in this way, but not subdirectories--you must use i to reinsert a subdirectory.

The files in a Dired buffers are normally listed in alphabetical order by file names. Alternatively Dired can sort them by date/time. The Dired command s (dired-sort-toggle-or-edit) switches between these two sorting modes. The mode line in a Dired buffer indicates which way it is currently sorted--by name, or by date.

C-u s switches RET lets you specify a new value for dired-listing-switches.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AB.15 Dired and find

You can select a set of files for display in a Dired buffer more flexibly by using the find utility to choose the files.

To search for files with names matching a wildcard pattern use M-x find-name-dired. It reads arguments directory and pattern, and chooses all the files in directory or its subdirectories whose individual names match pattern.

The files thus chosen are displayed in a Dired buffer in which the ordinary Dired commands are available.

If you want to test the contents of files, rather than their names, use M-x find-grep-dired. This command reads two minibuffer arguments, directory and regexp; it chooses all the files in directory or its subdirectories that contain a match for regexp. It works by running the programs find and grep. See also M-x grep-find, in V.1 Running Compilations under Emacs. Remember to write the regular expression for grep, not for Emacs. (An alternative method of showing files whose contents match a given regexp is the % g regexp command, see AB.6 Dired Marks vs. Flags.)

The most general command in this series is M-x find-dired, which lets you specify any condition that find can test. It takes two minibuffer arguments, directory and find-args; it runs find in directory, passing find-args to tell find what condition to test. To use this command, you need to know how to use find.

M-x locate provides a similar interface to the locate program. M-x locate-with-filter is similar, but keeps only lines matching a given regular expression.

The format of listing produced by these commands is controlled by the variable find-ls-option, whose default value specifies using options `-ld' for ls. If your listings are corrupted, you may need to change the value of this variable.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated on April 2, 2002 using texi2html