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