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