Merge from trunk
[bpt/emacs.git] / doc / emacs / dired.texi
CommitLineData
8cf51b2c 1@c This is part of the Emacs manual.
73b0cd50 2@c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2011
4ebe9902 3@c Free Software Foundation, Inc.
8cf51b2c
GM
4@c See file emacs.texi for copying conditions.
5@node Dired, Calendar/Diary, Rmail, Top
6@chapter Dired, the Directory Editor
59eda47f
RS
7@c This node is referenced in the tutorial. When renaming or deleting
8@c it, the tutorial needs to be adjusted.
8cf51b2c
GM
9@cindex Dired
10@cindex file management
11
12 Dired makes an Emacs buffer containing a listing of a directory, and
13optionally some of its subdirectories as well. You can use the normal
fac6225b
CY
14Emacs commands to move around in this buffer, and special Dired
15commands to operate on the listed files.
8cf51b2c
GM
16
17 The Dired buffer is ``read-only,'' and inserting text in it is not
fac6225b
CY
18allowed. Ordinary printing characters such as @kbd{d} and @kbd{x} are
19redefined for special Dired commands. Some Dired commands @dfn{mark}
20or @dfn{flag} the @dfn{current file} (that is, the file on the current
21line); other commands operate on the marked files or on the flagged
22files. You first mark certain files in order to operate on all of
23them with one command.
8cf51b2c
GM
24
25 The Dired-X package provides various extra features for Dired mode.
26@xref{Top, Dired-X,,dired-x, Dired Extra Version 2 User's Manual}.
27
fac6225b
CY
28 You can also view a list of files in a directory with @kbd{C-x C-d}
29(@code{list-directory}). Unlike Dired, this command does not allow
30you to operate on the listed files. @xref{Directories}.
31
8cf51b2c
GM
32@menu
33* Enter: Dired Enter. How to invoke Dired.
34* Navigation: Dired Navigation. Special motion commands in the Dired buffer.
35* Deletion: Dired Deletion. Deleting files with Dired.
36* Flagging Many Files:: Flagging files based on their names.
37* Visit: Dired Visiting. Other file operations through Dired.
8838673e
GM
38* Marks vs Flags:: Flagging for deletion vs marking.
39* Operating on Files:: How to copy, rename, print, compress, etc.
40 either one file or several files.
8cf51b2c
GM
41* Shell Commands in Dired:: Running a shell command on the marked files.
42* Transforming File Names:: Using patterns to rename multiple files.
8838673e 43* Comparison in Dired:: Running `diff' by way of Dired.
8cf51b2c
GM
44* Subdirectories in Dired:: Adding subdirectories to the Dired buffer.
45@ifnottex
46* Subdir Switches:: Subdirectory switches in Dired.
47@end ifnottex
8838673e 48* Subdirectory Motion:: Moving across subdirectories, and up and down.
8cf51b2c
GM
49* Hiding Subdirectories:: Making subdirectories visible or invisible.
50* Updating: Dired Updating. Discarding lines for files of no interest.
8838673e 51* Find: Dired and Find. Using `find' to choose the files for Dired.
8cf51b2c 52* Wdired:: Operating on files by editing the Dired buffer.
c5ae942b 53* Image-Dired:: Viewing image thumbnails in Dired.
8cf51b2c
GM
54* Misc: Misc Dired Features. Various other features.
55@end menu
56
57@node Dired Enter
58@section Entering Dired
59
60@findex dired
61@kindex C-x d
62@vindex dired-listing-switches
fac6225b
CY
63 To invoke Dired, type @kbd{C-x d} (@code{dired}). This reads a
64directory name using the minibuffer, and opens a @dfn{Dired buffer}
65listing the files in that directory. You can also supply a wildcard
66file name pattern as the minibuffer argument, in which case the Dired
67buffer lists all files matching that pattern. The usual history and
68completion commands can be used in the minibuffer; in particular,
69@kbd{M-n} puts the name of the visited file (if any) in the minibuffer
70(@pxref{Minibuffer History}).
71
72 You can also invoke Dired by giving @kbd{C-x C-f} (@code{find-file})
73a directory name.
8cf51b2c
GM
74
75 The variable @code{dired-listing-switches} specifies the options to
76give to @code{ls} for listing the directory; this string @emph{must}
89532a07
CY
77contain @samp{-l}. If you use a prefix argument with the @code{dired}
78command, you can specify the @code{ls} switches with the minibuffer
79before you enter the directory specification. No matter how they are
80specified, the @code{ls} switches can include short options (that is,
81single characters) requiring no arguments, and long options (starting
82with @samp{--}) whose arguments are specified with @samp{=}.
8cf51b2c
GM
83
84 On MS-Windows and MS-DOS systems, Emacs @emph{emulates} @code{ls};
85see @ref{ls in Lisp}, for options and peculiarities of that emulation.
86
8cf51b2c
GM
87@findex dired-other-window
88@kindex C-x 4 d
89@findex dired-other-frame
90@kindex C-x 5 d
91 To display the Dired buffer in another window rather than in the
92selected window, use @kbd{C-x 4 d} (@code{dired-other-window}) instead
93of @kbd{C-x d}. @kbd{C-x 5 d} (@code{dired-other-frame}) uses a
94separate frame to display the Dired buffer.
95
96@node Dired Navigation
97@section Navigation in the Dired Buffer
98
99@kindex C-n @r{(Dired)}
100@kindex C-p @r{(Dired)}
101 All the usual Emacs cursor motion commands are available in Dired
102buffers. The keys @kbd{C-n} and @kbd{C-p} are redefined to put the
103cursor at the beginning of the file name on the line, rather than at
104the beginning of the line.
105
106@kindex SPC @r{(Dired)}
107 For extra convenience, @key{SPC} and @kbd{n} in Dired are equivalent
fac6225b
CY
108to @kbd{C-n}. @kbd{p} is equivalent to @kbd{C-p}. (Moving by lines
109is so common in Dired that it deserves to be easy to type.) @key{DEL}
110(move up and unflag) is also often useful simply for moving up
111(@pxref{Dired Deletion}).
8cf51b2c
GM
112
113@findex dired-goto-file
114@kindex j @r{(Dired)}
fac6225b
CY
115 @kbd{j} (@code{dired-goto-file}) prompts for a file name using the
116minibuffer, and moves point to the line in the Dired buffer describing
117that file.
118
119@cindex searching Dired buffers
120@vindex dired-isearch-filenames
121 @kbd{M-s f C-s} (@code{dired-isearch-filenames}) performs a forward
122incremental search in the Dired buffer, looking for matches only
123amongst the file names and ignoring the rest of the text in the
124buffer. @kbd{M-s f M-C-s} (@code{dired-isearch-filenames-regexp})
125does the same, using a regular expression search. If you change the
13989ab1 126variable @code{dired-isearch-filenames} to @code{t}, then the
fac6225b 127usual search commands also limit themselves to the file names; for
607f5f88
JL
128instance, @kbd{C-s} behaves like @kbd{M-s f C-s}. If the value is
129@code{dwim}, then search commands match the file names only when point
130was on a file name initially. @xref{Search}, for information about
131incremental search.
8cf51b2c
GM
132
133 Some additional navigation commands are available when the Dired
134buffer includes several directories. @xref{Subdirectory Motion}.
135
136@node Dired Deletion
137@section Deleting Files with Dired
138@cindex flagging files (in Dired)
139@cindex deleting files (in Dired)
140
141 One of the most frequent uses of Dired is to first @dfn{flag} files for
142deletion, then delete the files that were flagged.
143
144@table @kbd
145@item d
146Flag this file for deletion.
147@item u
148Remove deletion flag on this line.
149@item @key{DEL}
150Move point to previous line and remove the deletion flag on that line.
151@item x
152Delete the files that are flagged for deletion.
153@end table
154
155@kindex d @r{(Dired)}
156@findex dired-flag-file-deletion
157 You can flag a file for deletion by moving to the line describing
158the file and typing @kbd{d} (@code{dired-flag-file-deletion}). The
159deletion flag is visible as a @samp{D} at the beginning of the line.
160This command moves point to the next line, so that repeated @kbd{d}
161commands flag successive files. A numeric argument serves as a repeat
162count.
163
164@kindex u @r{(Dired deletion)}
165@kindex DEL @r{(Dired)}
166 The reason for flagging files for deletion, rather than deleting
167files immediately, is to reduce the danger of deleting a file
168accidentally. Until you direct Dired to delete the flagged files, you
169can remove deletion flags using the commands @kbd{u} and @key{DEL}.
170@kbd{u} (@code{dired-unmark}) works just like @kbd{d}, but removes
171flags rather than making flags. @key{DEL}
172(@code{dired-unmark-backward}) moves upward, removing flags; it is
173like @kbd{u} with argument @minus{}1.
174
175@kindex x @r{(Dired)}
176@findex dired-do-flagged-delete
8cf51b2c 177 To delete the flagged files, type @kbd{x}
fac6225b
CY
178(@code{dired-do-flagged-delete}). This command first displays a list
179of all the file names flagged for deletion, and requests confirmation
180with @kbd{yes}. If you confirm, Dired deletes the flagged files, then
181deletes their lines from the text of the Dired buffer. The Dired
182buffer, with somewhat fewer lines, remains selected.
8cf51b2c
GM
183
184 If you answer @kbd{no} or quit with @kbd{C-g} when asked to confirm, you
185return immediately to Dired, with the deletion flags still present in
186the buffer, and no files actually deleted.
187
188@cindex recursive deletion
189@vindex dired-recursive-deletes
190 You can delete empty directories just like other files, but normally
191Dired cannot delete directories that are nonempty. If the variable
192@code{dired-recursive-deletes} is non-@code{nil}, then Dired can
193delete nonempty directories including all their contents. That can
194be somewhat risky.
195
f2d7be88
CY
196@vindex delete-by-moving-to-trash
197 On some systems, there is a facility called the ``Trash'' or
198``Recycle Bin'', but Emacs does @emph{not} use it by default. Thus,
199when you delete a file in Dired, it is gone forever. However, you can
200tell Emacs to use the Trash for file deletion, by changing the
201variable @code{delete-by-moving-to-trash} to @code{t}. @xref{Misc
202File Ops}, for more information about the Trash.
203
8cf51b2c
GM
204@node Flagging Many Files
205@section Flagging Many Files at Once
206@cindex flagging many files for deletion (in Dired)
207
fac6225b
CY
208 The @kbd{#}, @kbd{~}, @kbd{.}, @kbd{% &}, and @kbd{% d} commands
209flag many files for deletion, based on their file names:
210
8cf51b2c
GM
211@table @kbd
212@item #
213Flag all auto-save files (files whose names start and end with @samp{#})
214for deletion (@pxref{Auto Save}).
215
216@item ~
217Flag all backup files (files whose names end with @samp{~}) for deletion
218(@pxref{Backup}).
219
8cf51b2c
GM
220@item .@: @r{(Period)}
221Flag excess numeric backup files for deletion. The oldest and newest
222few backup files of any one file are exempt; the middle ones are
223flagged.
224
fac6225b
CY
225@item % &
226Flag for deletion all files with certain kinds of names which suggest
227you could easily create those files again.
228
8cf51b2c
GM
229@item % d @var{regexp} @key{RET}
230Flag for deletion all files whose names match the regular expression
231@var{regexp}.
232@end table
233
8cf51b2c
GM
234@kindex # @r{(Dired)}
235@findex dired-flag-auto-save-files
236@cindex deleting auto-save files
fac6225b
CY
237 @kbd{#} (@code{dired-flag-auto-save-files}) flags all files whose
238names look like auto-save files---that is, files whose names begin and
239end with @samp{#}. @xref{Auto Save}.
8cf51b2c
GM
240
241@kindex ~ @r{(Dired)}
242@findex dired-flag-backup-files
fac6225b
CY
243 @kbd{~} (@code{dired-flag-backup-files}) flags all files whose names
244say they are backup files---that is, files whose names end in
245@samp{~}. @xref{Backup}.
8cf51b2c
GM
246
247@kindex . @r{(Dired)}
248@vindex dired-kept-versions
249@findex dired-clean-directory
fac6225b
CY
250 @kbd{.} (period, @code{dired-clean-directory}) flags just some of
251the backup files for deletion: all but the oldest few and newest few
252backups of any one file. Normally, the number of newest versions kept
253for each file is given by the variable @code{dired-kept-versions}
254(@strong{not} @code{kept-new-versions}; that applies only when
255saving). The number of oldest versions to keep is given by the
256variable @code{kept-old-versions}.
8cf51b2c
GM
257
258 Period with a positive numeric argument, as in @kbd{C-u 3 .},
259specifies the number of newest versions to keep, overriding
260@code{dired-kept-versions}. A negative numeric argument overrides
261@code{kept-old-versions}, using minus the value of the argument to
262specify the number of oldest versions of each file to keep.
263
fac6225b
CY
264@kindex % & @r{(Dired)}
265@findex dired-flag-garbage-files
266@vindex dired-garbage-files-regexp
267@cindex deleting some backup files
268 @kbd{% &} (@code{dired-flag-garbage-files}) flags files whose names
269match the regular expression specified by the variable
270@code{dired-garbage-files-regexp}. By default, this matches certain
271files produced by @TeX{}, @samp{.bak} files, and the @samp{.orig} and
272@samp{.rej} files produced by @code{patch}.
273
8cf51b2c
GM
274@findex dired-flag-files-regexp
275@kindex % d @r{(Dired)}
fac6225b
CY
276 @kbd{% d} flags all files whose names match a specified regular
277expression (@code{dired-flag-files-regexp}). Only the non-directory
278part of the file name is used in matching. You can use @samp{^} and
279@samp{$} to anchor matches. You can exclude certain subdirectories
280from marking by hiding them while you use @kbd{% d}. @xref{Hiding
281Subdirectories}.
8cf51b2c
GM
282
283@node Dired Visiting
284@section Visiting Files in Dired
285
286 There are several Dired commands for visiting or examining the files
287listed in the Dired buffer. All of them apply to the current line's
288file; if that file is really a directory, these commands invoke Dired on
289that subdirectory (making a separate Dired buffer).
290
291@table @kbd
292@item f
293@kindex f @r{(Dired)}
294@findex dired-find-file
295Visit the file described on the current line, like typing @kbd{C-x C-f}
296and supplying that file name (@code{dired-find-file}). @xref{Visiting}.
297
298@item @key{RET}
299@itemx e
300@kindex RET @r{(Dired)}
301@kindex e @r{(Dired)}
302Equivalent to @kbd{f}.
303
304@ignore @c This command seems too risky to document at all.
305@item a
306@kindex a @r{(Dired)}
307@findex dired-find-alternate-file
308Like @kbd{f}, but replaces the contents of the Dired buffer with
309that of an alternate file or directory (@code{dired-find-alternate-file}).
310@end ignore
311
312@item o
313@kindex o @r{(Dired)}
314@findex dired-find-file-other-window
315Like @kbd{f}, but uses another window to display the file's buffer
316(@code{dired-find-file-other-window}). The Dired buffer remains visible
317in the first window. This is like using @kbd{C-x 4 C-f} to visit the
318file. @xref{Windows}.
319
320@item C-o
321@kindex C-o @r{(Dired)}
322@findex dired-display-file
323Visit the file described on the current line, and display the buffer in
324another window, but do not select that window (@code{dired-display-file}).
325
326@item Mouse-1
327@itemx Mouse-2
328@findex dired-mouse-find-file-other-window
329Visit the file named by the line you click on
330(@code{dired-mouse-find-file-other-window}). This uses another window
331to display the file, like the @kbd{o} command.
332
333@item v
334@kindex v @r{(Dired)}
335@findex dired-view-file
336View the file described on the current line, using @kbd{M-x view-file}
337(@code{dired-view-file}). Viewing a file with @code{view-file} is
338like visiting it, but is slanted toward moving around in the file
339conveniently and does not allow changing the file. @xref{Misc File
340Ops, View File, Miscellaneous File Operations}.
341
342@item ^
343@kindex ^ @r{(Dired)}
344@findex dired-up-directory
345Visit the parent directory of the current directory
346(@code{dired-up-directory}). This is equivalent to moving to the line
347for @file{..} and typing @kbd{f} there.
348@end table
349
350@node Marks vs Flags
351@section Dired Marks vs. Flags
352
353@cindex marking many files (in Dired)
354 Instead of flagging a file with @samp{D}, you can @dfn{mark} the
355file with some other character (usually @samp{*}). Most Dired
356commands to operate on files use the files marked with @samp{*}. The
fac6225b 357only command that operates on flagged files is @kbd{x}, which deletes
8cf51b2c
GM
358them.
359
360 Here are some commands for marking with @samp{*}, for unmarking, and
361for operating on marks. (@xref{Dired Deletion}, for commands to flag
362and unflag files.)
363
364@table @kbd
365@item m
366@itemx * m
367@kindex m @r{(Dired)}
368@kindex * m @r{(Dired)}
369@findex dired-mark
370Mark the current file with @samp{*} (@code{dired-mark}). With a numeric
371argument @var{n}, mark the next @var{n} files starting with the current
372file. (If @var{n} is negative, mark the previous @minus{}@var{n}
373files.)
374
375@item * *
376@kindex * * @r{(Dired)}
377@findex dired-mark-executables
378@cindex marking executable files (in Dired)
379Mark all executable files with @samp{*}
380(@code{dired-mark-executables}). With a numeric argument, unmark all
381those files.
382
383@item * @@
384@kindex * @@ @r{(Dired)}
385@findex dired-mark-symlinks
386@cindex marking symbolic links (in Dired)
387Mark all symbolic links with @samp{*} (@code{dired-mark-symlinks}).
388With a numeric argument, unmark all those files.
389
390@item * /
391@kindex * / @r{(Dired)}
392@findex dired-mark-directories
393@cindex marking subdirectories (in Dired)
394Mark with @samp{*} all files which are directories, except for
395@file{.} and @file{..} (@code{dired-mark-directories}). With a numeric
396argument, unmark all those files.
397
398@item * s
399@kindex * s @r{(Dired)}
400@findex dired-mark-subdir-files
401Mark all the files in the current subdirectory, aside from @file{.}
402and @file{..} (@code{dired-mark-subdir-files}).
403
404@item u
405@itemx * u
406@kindex u @r{(Dired)}
407@kindex * u @r{(Dired)}
408@findex dired-unmark
409Remove any mark on this line (@code{dired-unmark}).
410
411@item @key{DEL}
412@itemx * @key{DEL}
413@kindex * DEL @r{(Dired)}
414@findex dired-unmark-backward
415@cindex unmarking files (in Dired)
416Move point to previous line and remove any mark on that line
417(@code{dired-unmark-backward}).
418
419@item * !
420@itemx U
421@kindex * ! @r{(Dired)}
422@kindex U @r{(Dired)}
423@findex dired-unmark-all-marks
424Remove all marks from all the files in this Dired buffer
425(@code{dired-unmark-all-marks}).
426
427@item * ? @var{markchar}
428@itemx M-@key{DEL}
429@kindex * ? @r{(Dired)}
430@kindex M-DEL @r{(Dired)}
431@findex dired-unmark-all-files
432Remove all marks that use the character @var{markchar}
433(@code{dired-unmark-all-files}). The argument is a single
434character---do not use @key{RET} to terminate it. See the description
435of the @kbd{* c} command below, which lets you replace one mark
436character with another.
437
438With a numeric argument, this command queries about each marked file,
439asking whether to remove its mark. You can answer @kbd{y} meaning yes,
440@kbd{n} meaning no, or @kbd{!} to remove the marks from the remaining
441files without asking about them.
442
443@item * C-n
444@itemx M-@}
445@findex dired-next-marked-file
446@kindex * C-n @r{(Dired)}
447@kindex M-@} @r{(Dired)}
448Move down to the next marked file (@code{dired-next-marked-file})
449A file is ``marked'' if it has any kind of mark.
450
451@item * C-p
452@itemx M-@{
453@findex dired-prev-marked-file
454@kindex * C-p @r{(Dired)}
455@kindex M-@{ @r{(Dired)}
456Move up to the previous marked file (@code{dired-prev-marked-file})
457
458@item t
459@itemx * t
460@kindex t @r{(Dired)}
461@kindex * t @r{(Dired)}
462@findex dired-toggle-marks
463@cindex toggling marks (in Dired)
464Toggle all marks (@code{dired-toggle-marks}): files marked with @samp{*}
465become unmarked, and unmarked files are marked with @samp{*}. Files
466marked in any other way are not affected.
467
468@item * c @var{old-markchar} @var{new-markchar}
469@kindex * c @r{(Dired)}
470@findex dired-change-marks
471Replace all marks that use the character @var{old-markchar} with marks
472that use the character @var{new-markchar} (@code{dired-change-marks}).
473This command is the primary way to create or use marks other than
474@samp{*} or @samp{D}. The arguments are single characters---do not use
475@key{RET} to terminate them.
476
477You can use almost any character as a mark character by means of this
478command, to distinguish various classes of files. If @var{old-markchar}
479is a space (@samp{ }), then the command operates on all unmarked files;
480if @var{new-markchar} is a space, then the command unmarks the files it
481acts on.
482
483To illustrate the power of this command, here is how to put @samp{D}
484flags on all the files that have no marks, while unflagging all those
485that already have @samp{D} flags:
486
487@example
488* c D t * c SPC D * c t SPC
489@end example
490
491This assumes that no files were already marked with @samp{t}.
492
493@item % m @var{regexp} @key{RET}
494@itemx * % @var{regexp} @key{RET}
495@findex dired-mark-files-regexp
496@kindex % m @r{(Dired)}
497@kindex * % @r{(Dired)}
498Mark (with @samp{*}) all files whose names match the regular expression
499@var{regexp} (@code{dired-mark-files-regexp}). This command is like
500@kbd{% d}, except that it marks files with @samp{*} instead of flagging
501with @samp{D}.
502
503Only the non-directory part of the file name is used in matching. Use
504@samp{^} and @samp{$} to anchor matches. You can exclude
505subdirectories by temporarily hiding them (@pxref{Hiding
506Subdirectories}).
507
508@item % g @var{regexp} @key{RET}
509@findex dired-mark-files-containing-regexp
510@kindex % g @r{(Dired)}
511@cindex finding files containing regexp matches (in Dired)
512Mark (with @samp{*}) all files whose @emph{contents} contain a match for
513the regular expression @var{regexp}
514(@code{dired-mark-files-containing-regexp}). This command is like
515@kbd{% m}, except that it searches the file contents instead of the file
516name.
517
518@item C-x u
519@itemx C-_
520@itemx C-/
521@kindex C-_ @r{(Dired)}
522@findex dired-undo
523Undo changes in the Dired buffer, such as adding or removing
524marks (@code{dired-undo}). @emph{This command does not revert the
525actual file operations, nor recover lost files!} It just undoes
526changes in the buffer itself.
527
528In some cases, using this after commands that operate on files can
529cause trouble. For example, after renaming one or more files,
530@code{dired-undo} restores the original names in the Dired buffer,
531which gets the Dired buffer out of sync with the actual contents of
532the directory.
533@end table
534
535@node Operating on Files
536@section Operating on Files
537@cindex operating on files in Dired
538
539 This section describes the basic Dired commands to operate on one file
540or several files. All of these commands are capital letters; all of
541them use the minibuffer, either to read an argument or to ask for
542confirmation, before they act. All of them let you specify the
543files to manipulate in these ways:
544
545@itemize @bullet
546@item
547If you give the command a numeric prefix argument @var{n}, it operates
548on the next @var{n} files, starting with the current file. (If @var{n}
549is negative, the command operates on the @minus{}@var{n} files preceding
550the current line.)
551
552@item
553Otherwise, if some files are marked with @samp{*}, the command operates
554on all those files.
555
556@item
557Otherwise, the command operates on the current file only.
558@end itemize
559
560@noindent
561Certain other Dired commands, such as @kbd{!} and the @samp{%}
562commands, use the same conventions to decide which files to work on.
563
564@vindex dired-dwim-target
565@cindex two directories (in Dired)
566 Commands which ask for a destination directory, such as those which
567copy and rename files or create links for them, try to guess the default
568target directory for the operation. Normally, they suggest the Dired
569buffer's default directory, but if the variable @code{dired-dwim-target}
570is non-@code{nil}, and if there is another Dired buffer displayed in the
571next window, that other buffer's directory is suggested instead.
572
573 Here are the file-manipulating Dired commands that operate on files.
574
575@table @kbd
576@findex dired-do-copy
577@kindex C @r{(Dired)}
578@cindex copying files (in Dired)
579@item C @var{new} @key{RET}
580Copy the specified files (@code{dired-do-copy}). The argument @var{new}
581is the directory to copy into, or (if copying a single file) the new
582name. This is like the shell command @code{cp}.
583
584@vindex dired-copy-preserve-time
585If @code{dired-copy-preserve-time} is non-@code{nil}, then copying
586with this command preserves the modification time of the old file in
587the copy, like @samp{cp -p}.
588
589@vindex dired-recursive-copies
590@cindex recursive copying
591The variable @code{dired-recursive-copies} controls whether to copy
592directories recursively (like @samp{cp -r}). The default is
593@code{nil}, which means that directories cannot be copied.
594
595@item D
596@findex dired-do-delete
597@kindex D @r{(Dired)}
598Delete the specified files (@code{dired-do-delete}). This is like the
599shell command @code{rm}.
600
601Like the other commands in this section, this command operates on the
602@emph{marked} files, or the next @var{n} files. By contrast, @kbd{x}
603(@code{dired-do-flagged-delete}) deletes all @dfn{flagged} files.
604
605@findex dired-do-rename
606@kindex R @r{(Dired)}
607@cindex renaming files (in Dired)
608@cindex moving files (in Dired)
609@item R @var{new} @key{RET}
610Rename the specified files (@code{dired-do-rename}). If you rename a
611single file, the argument @var{new} is the new name of the file. If
612you rename several files, the argument @var{new} is the directory into
613which to move the files (this is like the shell command @code{mv}).
614
615Dired automatically changes the visited file name of buffers associated
616with renamed files so that they refer to the new names.
617
618@findex dired-do-hardlink
619@kindex H @r{(Dired)}
620@cindex hard links (in Dired)
621@item H @var{new} @key{RET}
622Make hard links to the specified files (@code{dired-do-hardlink}).
623This is like the shell command @code{ln}. The argument @var{new} is
624the directory to make the links in, or (if making just one link) the
625name to give the link.
626
627@findex dired-do-symlink
628@kindex S @r{(Dired)}
629@cindex symbolic links (creation in Dired)
630@item S @var{new} @key{RET}
631Make symbolic links to the specified files (@code{dired-do-symlink}).
632This is like @samp{ln -s}. The argument @var{new} is the directory to
633make the links in, or (if making just one link) the name to give the
634link.
635
636@findex dired-do-chmod
637@kindex M @r{(Dired)}
638@cindex changing file permissions (in Dired)
639@item M @var{modespec} @key{RET}
640Change the mode (also called ``permission bits'') of the specified files
641(@code{dired-do-chmod}). This uses the @code{chmod} program, so
642@var{modespec} can be any argument that @code{chmod} can handle.
643
644@findex dired-do-chgrp
645@kindex G @r{(Dired)}
646@cindex changing file group (in Dired)
647@item G @var{newgroup} @key{RET}
648Change the group of the specified files to @var{newgroup}
649(@code{dired-do-chgrp}).
650
651@findex dired-do-chown
652@kindex O @r{(Dired)}
653@cindex changing file owner (in Dired)
654@item O @var{newowner} @key{RET}
655Change the owner of the specified files to @var{newowner}
656(@code{dired-do-chown}). (On most systems, only the superuser can do
657this.)
658
659@vindex dired-chown-program
660The variable @code{dired-chown-program} specifies the name of the
661program to use to do the work (different systems put @code{chown} in
662different places).
663
664@findex dired-do-touch
665@kindex T @r{(Dired)}
666@cindex changing file time (in Dired)
667@item T @var{timestamp} @key{RET}
668Touch the specified files (@code{dired-do-touch}). This means
669updating their modification times to the present time. This is like
670the shell command @code{touch}.
671
672@findex dired-do-print
673@kindex P @r{(Dired)}
674@cindex printing files (in Dired)
675@item P @var{command} @key{RET}
676Print the specified files (@code{dired-do-print}). You must specify the
677command to print them with, but the minibuffer starts out with a
678suitable guess made using the variables @code{lpr-command} and
679@code{lpr-switches} (the same variables that @code{lpr-buffer} uses;
680@pxref{Printing}).
681
682@findex dired-do-compress
683@kindex Z @r{(Dired)}
684@cindex compressing files (in Dired)
685@item Z
686Compress the specified files (@code{dired-do-compress}). If the file
687appears to be a compressed file already, uncompress it instead.
688
86d7a550
DU
689@findex epa-dired-do-decrypt
690@kindex :d @r{(Dired)}
691@cindex decrypting files (in Dired)
692@item :d
693Decrypt the specified files (@code{epa-dired-do-decrypt}).
694@xref{Dired integration,,, epa, EasyPG Assistant User's Manual}.
695
696@findex epa-dired-do-verify
697@kindex :v @r{(Dired)}
698@cindex verifying digital signatures on files (in Dired)
699@item :v
700Verify digital signatures on the specified files (@code{epa-dired-do-verify}).
701@xref{Dired integration,,, epa, EasyPG Assistant User's Manual}.
702
703@findex epa-dired-do-sign
704@kindex :s @r{(Dired)}
705@cindex signing files (in Dired)
706@item :s
707Digitally sign the specified files (@code{epa-dired-do-sign}).
708@xref{Dired integration,,, epa, EasyPG Assistant User's Manual}.
709
710@findex epa-dired-do-encrypt
711@kindex :e @r{(Dired)}
712@cindex encrypting files (in Dired)
713@item :e
714Encrypt the specified files (@code{epa-dired-do-encrypt}).
715@xref{Dired integration,,, epa, EasyPG Assistant User's Manual}.
716
8cf51b2c
GM
717@findex dired-do-load
718@kindex L @r{(Dired)}
719@cindex loading several files (in Dired)
720@item L
721Load the specified Emacs Lisp files (@code{dired-do-load}).
722@xref{Lisp Libraries}.
723
724@findex dired-do-byte-compile
725@kindex B @r{(Dired)}
726@cindex byte-compiling several files (in Dired)
727@item B
728Byte compile the specified Emacs Lisp files
729(@code{dired-do-byte-compile}). @xref{Byte Compilation,, Byte
730Compilation, elisp, The Emacs Lisp Reference Manual}.
731
732@kindex A @r{(Dired)}
733@findex dired-do-search
734@cindex search multiple files (in Dired)
735@item A @var{regexp} @key{RET}
736Search all the specified files for the regular expression @var{regexp}
737(@code{dired-do-search}).
738
739This command is a variant of @code{tags-search}. The search stops at
740the first match it finds; use @kbd{M-,} to resume the search and find
741the next match. @xref{Tags Search}.
742
743@kindex Q @r{(Dired)}
744@findex dired-do-query-replace-regexp
745@cindex search and replace in multiple files (in Dired)
746@item Q @var{regexp} @key{RET} @var{to} @key{RET}
747Perform @code{query-replace-regexp} on each of the specified files,
748replacing matches for @var{regexp} with the string
749@var{to} (@code{dired-do-query-replace-regexp}).
750
751This command is a variant of @code{tags-query-replace}. If you exit the
752query replace loop, you can use @kbd{M-,} to resume the scan and replace
753more matches. @xref{Tags Search}.
754@end table
755
756@node Shell Commands in Dired
757@section Shell Commands in Dired
758@cindex shell commands, Dired
759
760@findex dired-do-shell-command
761@kindex ! @r{(Dired)}
762@kindex X @r{(Dired)}
763The Dired command @kbd{!} (@code{dired-do-shell-command}) reads a
764shell command string in the minibuffer and runs that shell command on
fac6225b
CY
765one or more files. The files that the shell command operates on are
766determined in the usual way for Dired commands (@pxref{Operating on
767Files}). The command @kbd{X} is a synonym for @kbd{!}.
8cf51b2c 768
fac6225b
CY
769 The command @kbd{&} (@code{dired-do-async-shell-command}) does the
770same, except that it runs the shell command asynchronously. You can
771also do this with @kbd{!}, by appending a @samp{&} character to the
772end of the shell command.
8cf51b2c 773
fac6225b
CY
774 For both @kbd{!} and @kbd{&}, the working directory for the shell
775command is the top-level directory of the Dired buffer.
776
777 If you tell @kbd{!} or @kbd{&} to operate on more than one file, the
778shell command string determines how those files are passed to the
779shell command:
8cf51b2c
GM
780
781@itemize @bullet
782@item
fac6225b 783If you use @samp{*} surrounded by whitespace in the command string,
8cf51b2c
GM
784then the command runs just once, with the list of file names
785substituted for the @samp{*}. The order of file names is the order of
786appearance in the Dired buffer.
787
788Thus, @kbd{! tar cf foo.tar * @key{RET}} runs @code{tar} on the entire
789list of file names, putting them into one tar file @file{foo.tar}.
790
791If you want to use @samp{*} as a shell wildcard with whitespace around
792it, write @samp{*""}. In the shell, this is equivalent to @samp{*};
fac6225b
CY
793but since the @samp{*} is not surrounded by whitespace, Dired does not
794treat it specially.
8cf51b2c
GM
795
796@item
fac6225b
CY
797Otherwise, if the command string contains @samp{?} surrounded by
798whitespace, Emacs runs the shell command once @emph{for each file},
799substituting the current file name for @samp{?} each time. You can
800use @samp{?} more than once in the command; the same file name
801replaces each occurrence.
8cf51b2c
GM
802
803@item
fac6225b
CY
804If the command string contains neither @samp{*} nor @samp{?}, Emacs
805runs the shell command once for each file, adding the file name is
806added at the end. For example, @kbd{! uudecode @key{RET}} runs
807@code{uudecode} on each file.
8cf51b2c
GM
808@end itemize
809
810 To iterate over the file names in a more complicated fashion, use an
811explicit shell loop. For example, here is how to uuencode each file,
812making the output file name by appending @samp{.uu} to the input file
813name:
814
815@example
816for file in * ; do uuencode "$file" "$file" >"$file".uu; done
817@end example
818
fac6225b
CY
819 The @kbd{!} and @kbd{&} commands do not attempt to update the Dired
820buffer to show new or modified files, because they don't know what
821files will be changed. Use the @kbd{g} command to update the Dired
822buffer (@pxref{Dired Updating}).
823
824 @xref{Single Shell}, for information about running shell commands
825outside Dired.
8cf51b2c
GM
826
827@node Transforming File Names
828@section Transforming File Names in Dired
829
830 This section describes Dired commands which alter file names in a
831systematic way. Each command operates on some or all of the marked
832files, using a new name made by transforming the existing name.
833
834 Like the basic Dired file-manipulation commands (@pxref{Operating on
835Files}), the commands described here operate either on the next
836@var{n} files, or on all files marked with @samp{*}, or on the current
837file. (To mark files, use the commands described in @ref{Marks vs
838Flags}.)
839
840 All of the commands described in this section work
841@emph{interactively}: they ask you to confirm the operation for each
842candidate file. Thus, you can select more files than you actually
843need to operate on (e.g., with a regexp that matches many files), and
844then filter the selected names by typing @kbd{y} or @kbd{n} when the
845command prompts for confirmation.
846
847@table @kbd
848@findex dired-upcase
849@kindex % u @r{(Dired)}
850@cindex upcase file names
851@item % u
852Rename each of the selected files to an upper-case name
853(@code{dired-upcase}). If the old file names are @file{Foo}
854and @file{bar}, the new names are @file{FOO} and @file{BAR}.
855
856@item % l
857@findex dired-downcase
858@kindex % l @r{(Dired)}
859@cindex downcase file names
860Rename each of the selected files to a lower-case name
861(@code{dired-downcase}). If the old file names are @file{Foo} and
862@file{bar}, the new names are @file{foo} and @file{bar}.
863
864@item % R @var{from} @key{RET} @var{to} @key{RET}
865@kindex % R @r{(Dired)}
866@findex dired-do-rename-regexp
867@itemx % C @var{from} @key{RET} @var{to} @key{RET}
868@kindex % C @r{(Dired)}
869@findex dired-do-copy-regexp
870@itemx % H @var{from} @key{RET} @var{to} @key{RET}
871@kindex % H @r{(Dired)}
872@findex dired-do-hardlink-regexp
873@itemx % S @var{from} @key{RET} @var{to} @key{RET}
874@kindex % S @r{(Dired)}
875@findex dired-do-symlink-regexp
876These four commands rename, copy, make hard links and make soft links,
877in each case computing the new name by regular-expression substitution
878from the name of the old file.
879@end table
880
881 The four regular-expression substitution commands effectively
882perform a search-and-replace on the selected file names. They read
883two arguments: a regular expression @var{from}, and a substitution
884pattern @var{to}; they match each ``old'' file name against
885@var{from}, and then replace the matching part with @var{to}. You can
886use @samp{\&} and @samp{\@var{digit}} in @var{to} to refer to all or
887part of what the pattern matched in the old file name, as in
888@code{replace-regexp} (@pxref{Regexp Replace}). If the regular
889expression matches more than once in a file name, only the first match
890is replaced.
891
892 For example, @kbd{% R ^.*$ @key{RET} x-\& @key{RET}} renames each
893selected file by prepending @samp{x-} to its name. The inverse of this,
894removing @samp{x-} from the front of each file name, is also possible:
895one method is @kbd{% R ^x-\(.*\)$ @key{RET} \1 @key{RET}}; another is
896@kbd{% R ^x- @key{RET} @key{RET}}. (Use @samp{^} and @samp{$} to anchor
897matches that should span the whole file name.)
898
899 Normally, the replacement process does not consider the files'
900directory names; it operates on the file name within the directory. If
901you specify a numeric argument of zero, then replacement affects the
902entire absolute file name including directory name. (A non-zero
903argument specifies the number of files to operate on.)
904
905 You may want to select the set of files to operate on using the same
906regexp @var{from} that you will use to operate on them. To do this,
907mark those files with @kbd{% m @var{from} @key{RET}}, then use the
908same regular expression in the command to operate on the files. To
909make this more convenient, the @kbd{%} commands to operate on files
910use the last regular expression specified in any @kbd{%} command as a
911default.
912
913@node Comparison in Dired
914@section File Comparison with Dired
915@cindex file comparison (in Dired)
916@cindex compare files (in Dired)
917
918 Here are two Dired commands that compare specified files using
919@code{diff}. They show the output in a buffer using Diff mode
920(@pxref{Comparing Files}).
921
922@table @kbd
923@item =
924@findex dired-diff
925@kindex = @r{(Dired)}
926Compare the current file (the file at point) with another file (the
927file at the mark) using the @code{diff} program (@code{dired-diff}).
928The file at the mark is the first argument of @code{diff}, and the
929file at point is the second argument. This refers to the ordinary
930Emacs mark, not Dired marks; use @kbd{C-@key{SPC}}
931(@code{set-mark-command}) to set the mark at the first file's line
932(@pxref{Setting Mark}).
933
934@findex dired-backup-diff
935@kindex M-= @r{(Dired)}
936@item M-=
937Compare the current file with its latest backup file
938(@code{dired-backup-diff}). If the current file is itself a backup,
939compare it with the file it is a backup of; this way, you can compare
940a file with any one of its backups.
941
942The backup file is the first file given to @code{diff}.
943@end table
944
945@node Subdirectories in Dired
946@section Subdirectories in Dired
947@cindex subdirectories in Dired
948@cindex expanding subdirectories in Dired
949
950 A Dired buffer displays just one directory in the normal case;
951but you can optionally include its subdirectories as well.
952
953 The simplest way to include multiple directories in one Dired buffer is
954to specify the options @samp{-lR} for running @code{ls}. (If you give a
955numeric argument when you run Dired, then you can specify these options
956in the minibuffer.) That produces a recursive directory listing showing
957all subdirectories at all levels.
958
959 More often, you will want to show only specific subdirectories. You
960can do this with the @kbd{i} command:
961
962@table @kbd
963@findex dired-maybe-insert-subdir
964@kindex i @r{(Dired)}
965@item i
966@cindex inserted subdirectory (Dired)
967@cindex in-situ subdirectory (Dired)
968Insert the contents of a subdirectory later in the buffer.
969@end table
970
971Use the @kbd{i} (@code{dired-maybe-insert-subdir}) command on a line
972that describes a file which is a directory. It inserts the contents of
973that directory into the same Dired buffer, and moves there. Inserted
974subdirectory contents follow the top-level directory of the Dired
975buffer, just as they do in @samp{ls -lR} output.
976
977If the subdirectory's contents are already present in the buffer, the
978@kbd{i} command just moves to it.
979
980In either case, @kbd{i} sets the Emacs mark before moving, so @kbd{C-u
981C-@key{SPC}} takes you back to the old position in the buffer (the line
367c9b7c
JL
982describing that subdirectory). You can also use @samp{^} to return
983to the parent directory in the same Dired buffer.
8cf51b2c
GM
984
985Use the @kbd{l} command (@code{dired-do-redisplay}) to update the
986subdirectory's contents. Use @kbd{C-u k} on the subdirectory header
e3e0fb39
GM
987line to delete the subdirectory (@pxref{Dired Updating}). You can also
988hide and show inserted subdirectories (@pxref{Hiding Subdirectories}).
8cf51b2c 989
8cf51b2c
GM
990@ifnottex
991@include dired-xtra.texi
992@end ifnottex
993
994@node Subdirectory Motion
995@section Moving Over Subdirectories
996
997 When a Dired buffer lists subdirectories, you can use the page motion
998commands @kbd{C-x [} and @kbd{C-x ]} to move by entire directories
999(@pxref{Pages}).
1000
1001@cindex header line (Dired)
1002@cindex directory header lines
1003 The following commands move across, up and down in the tree of
1004directories within one Dired buffer. They move to @dfn{directory header
1005lines}, which are the lines that give a directory's name, at the
1006beginning of the directory's contents.
1007
1008@table @kbd
1009@findex dired-next-subdir
1010@kindex C-M-n @r{(Dired)}
1011@item C-M-n
1012Go to next subdirectory header line, regardless of level
1013(@code{dired-next-subdir}).
1014
1015@findex dired-prev-subdir
1016@kindex C-M-p @r{(Dired)}
1017@item C-M-p
1018Go to previous subdirectory header line, regardless of level
1019(@code{dired-prev-subdir}).
1020
1021@findex dired-tree-up
1022@kindex C-M-u @r{(Dired)}
1023@item C-M-u
1024Go up to the parent directory's header line (@code{dired-tree-up}).
1025
1026@findex dired-tree-down
1027@kindex C-M-d @r{(Dired)}
1028@item C-M-d
1029Go down in the directory tree, to the first subdirectory's header line
1030(@code{dired-tree-down}).
1031
1032@findex dired-prev-dirline
1033@kindex < @r{(Dired)}
1034@item <
1035Move up to the previous directory-file line (@code{dired-prev-dirline}).
1036These lines are the ones that describe a directory as a file in its
1037parent directory.
1038
1039@findex dired-next-dirline
1040@kindex > @r{(Dired)}
1041@item >
1042Move down to the next directory-file line (@code{dired-prev-dirline}).
1043@end table
1044
1045@node Hiding Subdirectories
1046@section Hiding Subdirectories
8b74f389
BG
1047@cindex hiding subdirectories (Dired)
1048@cindex showing hidden subdirectories (Dired)
8cf51b2c 1049
8cf51b2c
GM
1050 @dfn{Hiding} a subdirectory means to make it invisible, except for its
1051header line.
1052
1053@table @kbd
1054@item $
1055@findex dired-hide-subdir
1056@kindex $ @r{(Dired)}
8b74f389
BG
1057Hide or show the subdirectory that point is in, and move point to the
1058next subdirectory (@code{dired-hide-subdir}). This is a toggle. A
1059numeric argument serves as a repeat count.
8cf51b2c
GM
1060
1061@item M-$
1062@findex dired-hide-all
1063@kindex M-$ @r{(Dired)}
1064Hide all subdirectories in this Dired buffer, leaving only their header
1065lines (@code{dired-hide-all}). Or, if any subdirectory is currently
1066hidden, make all subdirectories visible again. You can use this command
1067to get an overview in very deep directory trees or to move quickly to
1068subdirectories far away.
1069@end table
1070
1071 Ordinary Dired commands never consider files inside a hidden
1072subdirectory. For example, the commands to operate on marked files
1073ignore files in hidden directories even if they are marked. Thus you
1074can use hiding to temporarily exclude subdirectories from operations
1075without having to remove the Dired marks on files in those
1076subdirectories.
1077
e3e0fb39 1078@xref{Dired Updating}, for how to insert or delete a subdirectory listing.
8b74f389 1079
8cf51b2c
GM
1080@node Dired Updating
1081@section Updating the Dired Buffer
1082@cindex updating Dired buffer
1083@cindex refreshing displayed files
1084
1085 This section describes commands to update the Dired buffer to reflect
1086outside (non-Dired) changes in the directories and files, and to delete
1087part of the Dired buffer.
1088
1089@table @kbd
1090@item g
1091Update the entire contents of the Dired buffer (@code{revert-buffer}).
1092
1093@item l
1094Update the specified files (@code{dired-do-redisplay}). You specify the
1095files for @kbd{l} in the same way as for file operations.
1096
1097@item k
1098Delete the specified @emph{file lines}---not the files, just the lines
1099(@code{dired-do-kill-lines}).
1100
1101@item s
1102Toggle between alphabetical order and date/time order
1103(@code{dired-sort-toggle-or-edit}).
1104
1105@item C-u s @var{switches} @key{RET}
1106Refresh the Dired buffer using @var{switches} as
1107@code{dired-listing-switches}.
1108@end table
1109
1110@kindex g @r{(Dired)}
1111@findex revert-buffer @r{(Dired)}
1112 Type @kbd{g} (@code{revert-buffer}) to update the contents of the
1113Dired buffer, based on changes in the files and directories listed.
1114This preserves all marks except for those on files that have vanished.
1115Hidden subdirectories are updated but remain hidden.
1116
1117@kindex l @r{(Dired)}
1118@findex dired-do-redisplay
1119 To update only some of the files, type @kbd{l}
1120(@code{dired-do-redisplay}). Like the Dired file-operating commands,
1121this command operates on the next @var{n} files (or previous
1122@minus{}@var{n} files), or on the marked files if any, or on the
1123current file. Updating the files means reading their current status,
1124then updating their lines in the buffer to indicate that status.
1125
1126 If you use @kbd{l} on a subdirectory header line, it updates the
1127contents of the corresponding subdirectory.
1128
4102856c
CY
1129@vindex dired-auto-revert-buffer
1130 If you use @kbd{C-x d} or some other Dired command to visit a
1131directory that is already being shown in a Dired buffer, Dired
1132switches to that buffer but does not update it. If the buffer is not
1133up-to-date, Dired displays a warning telling you to type @key{g} to
1134update it. You can also tell Emacs to revert each Dired buffer
1135automatically when you revisit it, by setting the variable
1136@code{dired-auto-revert-buffer} to a non-@code{nil} value.
1137
8cf51b2c
GM
1138@kindex k @r{(Dired)}
1139@findex dired-do-kill-lines
1140 To delete the specified @emph{file lines} from the buffer---not
1141delete the files---type @kbd{k} (@code{dired-do-kill-lines}). Like
1142the file-operating commands, this command operates on the next @var{n}
1143files, or on the marked files if any; but it does not operate on the
1144current file as a last resort.
1145
1146 If you use @kbd{k} with a numeric prefix argument to kill the line
1147for a file that is a directory, which you have inserted in the Dired
1148buffer as a subdirectory, it deletes that subdirectory from the buffer
1149as well. Typing @kbd{C-u k} on the header line for a subdirectory
1150also deletes the subdirectory from the Dired buffer.
1151
1152 The @kbd{g} command brings back any individual lines that you have
1153killed in this way, but not subdirectories---you must use @kbd{i} to
1154reinsert a subdirectory.
1155
1156@cindex Dired sorting
1157@cindex sorting Dired buffer
1158@kindex s @r{(Dired)}
1159@findex dired-sort-toggle-or-edit
1160 The files in a Dired buffers are normally listed in alphabetical order
1161by file names. Alternatively Dired can sort them by date/time. The
1162Dired command @kbd{s} (@code{dired-sort-toggle-or-edit}) switches
1163between these two sorting modes. The mode line in a Dired buffer
1164indicates which way it is currently sorted---by name, or by date.
1165
1166 @kbd{C-u s @var{switches} @key{RET}} lets you specify a new value for
1167@code{dired-listing-switches}.
1168
1169@node Dired and Find
1170@section Dired and @code{find}
1171@cindex @code{find} and Dired
1172
1173 You can select a set of files for display in a Dired buffer more
fac6225b 1174flexibly by using the @command{find} utility to choose the files.
8cf51b2c
GM
1175
1176@findex find-name-dired
1177 To search for files with names matching a wildcard pattern use
1178@kbd{M-x find-name-dired}. It reads arguments @var{directory} and
1179@var{pattern}, and chooses all the files in @var{directory} or its
1180subdirectories whose individual names match @var{pattern}.
1181
1182 The files thus chosen are displayed in a Dired buffer, in which the
1183ordinary Dired commands are available.
1184
1185@findex find-grep-dired
1186 If you want to test the contents of files, rather than their names,
1187use @kbd{M-x find-grep-dired}. This command reads two minibuffer
fac6225b
CY
1188arguments, @var{directory} and @var{regexp}; it chooses all the files
1189in @var{directory} or its subdirectories that contain a match for
1190@var{regexp}. It works by running the programs @command{find} and
1191@command{grep}. See also @kbd{M-x grep-find}, in @ref{Grep
1192Searching}. Remember to write the regular expression for
1193@command{grep}, not for Emacs. (An alternative method of showing
1194files whose contents match a given regexp is the @kbd{% g
1195@var{regexp}} command, see @ref{Marks vs Flags}.)
8cf51b2c
GM
1196
1197@findex find-dired
fac6225b
CY
1198 The most general command in this series is @kbd{M-x find-dired},
1199which lets you specify any condition that @command{find} can test. It
1200takes two minibuffer arguments, @var{directory} and @var{find-args};
1201it runs @command{find} in @var{directory}, passing @var{find-args} to
1202tell @command{find} what condition to test. To use this command, you
1203need to know how to use @command{find}.
8cf51b2c
GM
1204
1205@vindex find-ls-option
1206 The format of listing produced by these commands is controlled by the
1207variable @code{find-ls-option}, whose default value specifies using
1208options @samp{-ld} for @code{ls}. If your listings are corrupted, you
1209may need to change the value of this variable.
1210
1211@findex locate
1212@findex locate-with-filter
1213@cindex file database (locate)
1214@vindex locate-command
1215 The command @kbd{M-x locate} provides a similar interface to the
fac6225b 1216@command{locate} program. @kbd{M-x locate-with-filter} is similar, but
8cf51b2c
GM
1217keeps only files whose names match a given regular expression.
1218
1219 These buffers don't work entirely like ordinary Dired buffers: file
1220operations work, but do not always automatically update the buffer.
1221Reverting the buffer with @kbd{g} deletes all inserted subdirectories,
1222and erases all flags and marks.
1223
1224@node Wdired
1225@section Editing the Dired Buffer
1226
1227@cindex wdired mode
1228@findex wdired-change-to-wdired-mode
1229 Wdired is a special mode that allows you to perform file operations
1230by editing the Dired buffer directly (the ``W'' in ``Wdired'' stands
fac6225b
CY
1231for ``writable.'') To enter Wdired mode, type @kbd{C-x C-q}
1232(@code{dired-toggle-read-only}) while in a Dired buffer.
1233Alternatively, use the @samp{Immediate / Edit File Names} menu item.
8cf51b2c
GM
1234
1235@findex wdired-finish-edit
1236 While in Wdired mode, you can rename files by editing the file names
1237displayed in the Dired buffer. All the ordinary Emacs editing
1238commands, including rectangle operations and @code{query-replace}, are
1239available for this. Once you are done editing, type @kbd{C-c C-c}
1240(@code{wdired-finish-edit}). This applies your changes and switches
1241back to ordinary Dired mode.
1242
1243 Apart from simply renaming files, you can move a file to another
1244directory by typing in the new file name (either absolute or
1245relative). To mark a file for deletion, delete the entire file name.
1246To change the target of a symbolic link, edit the link target name
1247which appears next to the link name.
1248
1249 The rest of the text in the buffer, such as the file sizes and
1250modification dates, is marked read-only, so you can't edit it.
1251However, if you set @code{wdired-allow-to-change-permissions} to
1252@code{t}, you can edit the file permissions. For example, you can
1253change @samp{-rw-r--r--} to @samp{-rw-rw-rw-} to make a file
1254world-writable. These changes also take effect when you type @kbd{C-c
1255C-c}.
1256
1257@node Image-Dired
1258@section Viewing Image Thumbnails in Dired
1259@cindex image-dired mode
1260@cindex image-dired
1261
1262 Image-Dired is a facility for browsing image files. It provides viewing
1263the images either as thumbnails or in full size, either inside Emacs
1264or through an external viewer.
1265
1266@kindex C-t d @r{(Image-Dired)}
1267@findex image-dired-display-thumbs
1268 To enter Image-Dired, mark the image files you want to look at in
1269the Dired buffer, using @kbd{m} as usual. Then type @kbd{C-t d}
1270(@code{image-dired-display-thumbs}). This creates and switches to a
1271buffer containing image-dired, corresponding to the marked files.
1272
1273 You can also enter Image-Dired directly by typing @kbd{M-x
1274image-dired}. This prompts for a directory; specify one that has
1275image files. This creates thumbnails for all the images in that
1276directory, and displays them all in the ``thumbnail buffer.'' This
1277takes a long time if the directory contains many image files, and it
1278asks for confirmation if the number of image files exceeds
1279@code{image-dired-show-all-from-dir-max-files}.
1280
1281 With point in the thumbnail buffer, you can type @kbd{RET}
1282(@code{image-dired-display-thumbnail-original-image}) to display a
1283sized version of it in another window. This sizes the image to fit
1284the window. Use the arrow keys to move around in the buffer. For
1285easy browsing, use @kbd{SPC}
1286(@code{image-dired-display-next-thumbnail-original}) to advance and
1287display the next image. Typing @kbd{DEL}
1288(@code{image-dired-display-previous-thumbnail-original}) backs up to
1289the previous thumbnail and displays that instead.
1290
1291@vindex image-dired-external-viewer
1292 To view and the image in its original size, either provide a prefix
1293argument (@kbd{C-u}) before pressing @kbd{RET}, or type
1294@kbd{C-@key{RET}} (@code{image-dired-thumbnail-display-external}) to
1295display the image in an external viewer. You must first configure
1296@code{image-dired-external-viewer}.
1297
1298 You can delete images through Image-Dired also. Type @kbd{d}
1299(@code{image-dired-flag-thumb-original-file}) to flag the image file
1300for deletion in the Dired buffer. You can also delete the thumbnail
1301image from the thumbnail buffer with @kbd{C-d}
1302(@code{image-dired-delete-char}).
1303
1304 More advanced features include @dfn{image tags}, which are metadata
1305used to categorize image files. The tags are stored in a plain text
1306file configured by @code{image-dired-db-file}.
1307
1308 To tag image files, mark them in the dired buffer (you can also mark
1309files in Dired from the thumbnail buffer by typing @kbd{m}) and type
39e26906
RS
1310@kbd{C-t t} (@code{image-dired-tag-files}). This reads the tag name
1311in the minibuffer. To mark files having a certain tag, type @kbd{C-t f}
8cf51b2c
GM
1312(@code{image-dired-mark-tagged-files}). After marking image files
1313with a certain tag, you can use @kbd{C-t d} to view them.
1314
1315 You can also tag a file directly from the thumbnail buffer by typing
1316@kbd{t t} and you can remove a tag by typing @kbd{t r}. There is also
1317a special ``tag'' called ``comment'' for each file (it is not a tag in
1318the exact same sense as the other tags, it is handled slightly
1319different). That is used to enter a comment or description about the
1320image. You comment a file from the thumbnail buffer by typing
1321@kbd{c}. You will be prompted for a comment. Type @kbd{C-t c} to add
1322a comment from Dired (@code{image-dired-dired-comment-files}).
1323
1324 Image-Dired also provides simple image manipulation. In the
1325thumbnail buffer, type @kbd{L} to rotate the original image 90 degrees
1326anti clockwise, and @kbd{R} to rotate it 90 degrees clockwise. This
1327rotation is lossless, and uses an external utility called JpegTRAN.
1328
1329@node Misc Dired Features
1330@section Other Dired Features
1331
1332@kindex + @r{(Dired)}
1333@findex dired-create-directory
fac6225b
CY
1334 The command @kbd{+} (@code{dired-create-directory}) reads a
1335directory name, and creates the directory if it does not already
1336exist.
1337
1338@cindex searching multiple files via Dired
1339 The command @kbd{M-s a C-s} (@code{dired-do-isearch}) begins a
1340``multi-file'' incremental search on the marked files. If a search
1341fails at the end of a file, typing @kbd{C-s} advances to the next
1342marked file and repeats the search; at the end of the last marked
1343file, the search wraps around to the first marked file. The command
1344@kbd{M-s a M-C-s} (@code{dired-do-isearch-regexp}) does the same with
1345a regular expression search. @xref{Repeat Isearch}, for information
1346about search repetition.
8cf51b2c
GM
1347
1348@cindex Adding to the kill ring in Dired.
1349@kindex w @r{(Dired)}
1350@findex dired-copy-filename-as-kill
fac6225b 1351 The command @kbd{w} (@code{dired-copy-filename-as-kill}) puts the
8cf51b2c 1352names of the marked (or next @var{n}) files into the kill ring, as if
fac6225b
CY
1353you had killed them with @kbd{C-w}. The names are separated by a
1354space.
8cf51b2c
GM
1355
1356 With a zero prefix argument, this uses the absolute file name of
1357each marked file. With just @kbd{C-u} as the prefix argument, it uses
1358file names relative to the Dired buffer's default directory. (This
1359can still contain slashes if in a subdirectory.) As a special case,
1360if point is on a directory headerline, @kbd{w} gives you the absolute
1361name of that directory. Any prefix argument or marked files are
1362ignored in this case.
1363
1364 The main purpose of this command is so that you can yank the file
1365names into arguments for other Emacs commands. It also displays what
1366it added to the kill ring, so you can use it to display the list of
1367currently marked files in the echo area.
1368
4ebe9902
GM
1369@cindex Dired and version control
1370 If the directory you are visiting is under version control
1371(@pxref{Version Control}), then the normal VC diff and log commands
1372will operate on the selected files.
1373
8cf51b2c
GM
1374@findex dired-compare-directories
1375 The command @kbd{M-x dired-compare-directories} is used to compare
1376the current Dired buffer with another directory. It marks all the files
1377that are ``different'' between the two directories. It puts these marks
1378in all Dired buffers where these files are listed, which of course includes
1379the current buffer.
1380
1381 The default comparison method (used if you type @key{RET} at the
1382prompt) is to compare just the file names---each file name that does
1383not appear in the other directory is ``different.'' You can specify
1384more stringent comparisons by entering a Lisp expression, which can
1385refer to the variables @code{size1} and @code{size2}, the respective
1386file sizes; @code{mtime1} and @code{mtime2}, the last modification
1387times in seconds, as floating point numbers; and @code{fa1} and
1388@code{fa2}, the respective file attribute lists (as returned by the
1389function @code{file-attributes}). This expression is evaluated for
1390each pair of like-named files, and if the expression's value is
1391non-@code{nil}, those files are considered ``different.''
1392
1393 For instance, the sequence @code{M-x dired-compare-directories
1394@key{RET} (> mtime1 mtime2) @key{RET}} marks files newer in this
1395directory than in the other, and marks files older in the other
1396directory than in this one. It also marks files with no counterpart,
1397in both directories, as always.
1398
1399@cindex drag and drop, Dired
1400 On the X window system, Emacs supports the ``drag and drop''
1401protocol. You can drag a file object from another program, and drop
1402it onto a Dired buffer; this either moves, copies, or creates a link
1403to the file in that directory. Precisely which action is taken is
1404determined by the originating program. Dragging files out of a Dired
1405buffer is currently not supported.