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