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