1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2018 Free Software
4 @c See file emacs.texi for copying conditions.
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.
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 normally read-only, and inserting text in it is
18 not allowed (however, the Wdired mode allows that, @pxref{Wdired}).
19 Ordinary printing characters such as @kbd{d} and @kbd{x} are
20 redefined for special Dired commands. Some Dired commands @dfn{mark}
21 or @dfn{flag} the @dfn{current file} (that is, the file on the current
22 line); other commands operate on the marked files or on the flagged
23 files. You first mark certain files in order to operate on all of
24 them with one command.
26 The Dired-X package provides various extra features for Dired mode.
27 @xref{Top, Dired-X,,dired-x, Dired Extra User's Manual}.
29 You can also view a list of files in a directory with @kbd{C-x C-d}
30 (@code{list-directory}). Unlike Dired, this command does not allow
31 you to operate on the listed files. @xref{Directories}.
34 * Enter: Dired Enter. How to invoke Dired.
35 * Navigation: Dired Navigation. Special motion commands in the Dired buffer.
36 * Deletion: Dired Deletion. Deleting files with Dired.
37 * Flagging Many Files:: Flagging files based on their names.
38 * Visit: Dired Visiting. Other file operations through Dired.
39 * Marks vs Flags:: Flagging for deletion vs marking.
40 * Operating on Files:: How to copy, rename, print, compress, etc.
41 either one file or several files.
42 * Shell Commands in Dired:: Running a shell command on the marked files.
43 * Transforming File Names:: Using patterns to rename multiple files.
44 * Comparison in Dired:: Running @code{diff} by way of Dired.
45 * Subdirectories in Dired:: Adding subdirectories to the Dired buffer.
47 * Subdir Switches:: Subdirectory switches in Dired.
49 * Subdirectory Motion:: Moving across subdirectories, and up and down.
50 * Hiding Subdirectories:: Making subdirectories visible or invisible.
51 * Updating: Dired Updating. Discarding lines for files of no interest.
52 * Find: Dired and Find. Using @code{find} to choose the files for Dired.
53 * Wdired:: Operating on files by editing the Dired buffer.
54 * Image-Dired:: Viewing image thumbnails in Dired.
55 * Misc: Misc Dired Features. Various other features.
59 @section Entering Dired
63 @vindex dired-listing-switches
64 To invoke Dired, type @kbd{C-x d} (@code{dired}). This reads a
65 directory's name using the minibuffer, and opens a @dfn{Dired buffer}
66 listing the files in that directory. You can also supply a wildcard
67 file name pattern as the minibuffer argument, in which case the Dired
68 buffer lists all files matching that pattern. A wildcard may appear
69 in the directory part as well.
73 C-x d ~/foo/*.el @key{RET}
74 C-x d ~/foo/*/*.el @key{RET}
77 The former lists all the files with extension @samp{.el} in directory
78 @samp{foo}. The latter lists the files with extension @samp{.el}
79 in all the subdirectories of @samp{foo}.
81 The usual history and completion commands can be used in the minibuffer;
82 in particular, @kbd{M-n} puts the name of the visited file (if any) in
83 the minibuffer (@pxref{Minibuffer History}).
85 You can also invoke Dired by giving @kbd{C-x C-f} (@code{find-file})
88 The variable @code{dired-listing-switches} specifies the options to
89 give to @command{ls} for listing the directory; this string
90 @emph{must} contain @samp{-l}. If you use a prefix argument with the
91 @code{dired} command, you can specify the @command{ls} switches with the
92 minibuffer before you enter the directory specification. No matter
93 how they are specified, the @command{ls} switches can include short
94 options (that is, single characters) requiring no arguments, and long
95 options (starting with @samp{--}) whose arguments are specified with
98 @vindex dired-use-ls-dired
99 If your @command{ls} program supports the @samp{--dired} option,
100 Dired automatically passes it that option; this causes @command{ls} to
101 emit special escape sequences for certain unusual file names, without
102 which Dired will not be able to parse those names. The first time you
103 run Dired in an Emacs session, it checks whether @command{ls} supports
104 the @samp{--dired} option by calling it once with that option. If the
105 exit code is 0, Dired will subsequently use the @samp{--dired} option;
106 otherwise it will not. You can inhibit this check by customizing the
107 variable @code{dired-use-ls-dired}. The value @code{unspecified} (the
108 default) means to perform the check; any other non-@code{nil} value
109 means to use the @samp{--dired} option; and @code{nil} means not to
110 use the @samp{--dired} option.
112 On MS-Windows and MS-DOS systems, Emacs emulates @command{ls}.
113 @xref{ls in Lisp}, for options and peculiarities of this emulation.
115 @findex dired-other-window
117 @findex dired-other-frame
119 To display the Dired buffer in another window, use @kbd{C-x 4 d}
120 (@code{dired-other-window}). @kbd{C-x 5 d}
121 (@code{dired-other-frame}) displays the Dired buffer in a separate
124 @kindex q @r{(Dired)}
125 @findex quit-window@r{, in Dired buffers}
126 Typing @kbd{q} (@code{quit-window}) buries the Dired buffer, and
127 deletes its window if the window was created just for that buffer.
129 @node Dired Navigation
130 @section Navigation in the Dired Buffer
132 @kindex C-n @r{(Dired)}
133 @kindex C-p @r{(Dired)}
134 All the usual Emacs cursor motion commands are available in Dired
135 buffers. The keys @kbd{C-n} and @kbd{C-p} are redefined to put the
136 cursor at the beginning of the file name on the line, rather than at
137 the beginning of the line.
139 @kindex SPC @r{(Dired)}
140 For extra convenience, @key{SPC} and @kbd{n} in Dired are equivalent
141 to @kbd{C-n}. @kbd{p} is equivalent to @kbd{C-p}. (Moving by lines
142 is so common in Dired that it deserves to be easy to type.) @key{DEL}
143 (move up and unflag) is also often useful simply for moving up
144 (@pxref{Dired Deletion}).
146 @findex dired-goto-file
147 @kindex j @r{(Dired)}
148 @kbd{j} (@code{dired-goto-file}) prompts for a file name using the
149 minibuffer, and moves point to the line in the Dired buffer describing
152 @cindex searching Dired buffers
153 @findex dired-isearch-filenames
154 @vindex dired-isearch-filenames
155 @findex dired-isearch-filenames-regexp
156 @kindex M-s f C-s @r{(Dired)}
157 @kindex M-s f M-C-s @r{(Dired)}
158 @kbd{M-s f C-s} (@code{dired-isearch-filenames}) performs a forward
159 incremental search in the Dired buffer, looking for matches only
160 amongst the file names and ignoring the rest of the text in the
161 buffer. @kbd{M-s f M-C-s} (@code{dired-isearch-filenames-regexp})
162 does the same, using a regular expression search. If you change the
163 variable @code{dired-isearch-filenames} to @code{t}, then the
164 usual search commands also limit themselves to the file names; for
165 instance, @kbd{C-s} behaves like @kbd{M-s f C-s}. If the value is
166 @code{dwim}, then search commands match the file names only when point
167 was on a file name initially. @xref{Search}, for information about
170 Some additional navigation commands are available when the Dired
171 buffer includes several directories. @xref{Subdirectory Motion}.
174 @section Deleting Files with Dired
175 @cindex flagging files (in Dired)
176 @cindex deleting files (in Dired)
178 One of the most frequent uses of Dired is to first @dfn{flag} files for
179 deletion, then delete the files that were flagged.
183 Flag this file for deletion (@code{dired-flag-file-deletion}).
185 Remove the deletion flag (@code{dired-unmark}).
187 Move point to previous line and remove the deletion flag on that line
188 (@code{dired-unmark-backward}).
190 Delete files flagged for deletion (@code{dired-do-flagged-delete}).
193 @kindex d @r{(Dired)}
194 @findex dired-flag-file-deletion
195 You can flag a file for deletion by moving to the line describing
196 the file and typing @kbd{d} (@code{dired-flag-file-deletion}). The
197 deletion flag is visible as a @samp{D} at the beginning of the line.
198 This command moves point to the next line, so that repeated @kbd{d}
199 commands flag successive files. A numeric prefix argument serves as a
200 repeat count; a negative count means to flag preceding files.
202 If the region is active, the @kbd{d} command flags all files in the
203 region for deletion; in this case, the command does not move point,
204 and ignores any prefix argument.
206 @kindex u @r{(Dired deletion)}
207 @kindex DEL @r{(Dired)}
208 The reason for flagging files for deletion, rather than deleting
209 files immediately, is to reduce the danger of deleting a file
210 accidentally. Until you direct Dired to delete the flagged files, you
211 can remove deletion flags using the commands @kbd{u} and @key{DEL}.
212 @kbd{u} (@code{dired-unmark}) works just like @kbd{d}, but removes
213 flags rather than making flags. @key{DEL}
214 (@code{dired-unmark-backward}) moves upward, removing flags; it is
215 like @kbd{u} with argument @minus{}1. A numeric prefix argument to
216 either command serves as a repeat count, with a negative count meaning
217 to unflag in the opposite direction. If the region is active, these
218 commands instead unflag all files in the region, without moving point.
220 @kindex x @r{(Dired)}
221 @findex dired-do-flagged-delete
222 To delete flagged files, type @kbd{x}
223 (@code{dired-do-flagged-delete}). This command displays a list of all
224 the file names flagged for deletion, and requests confirmation with
225 @kbd{yes}. If you confirm, Dired deletes the flagged files, then
226 deletes their lines from the text of the Dired buffer. The Dired
227 buffer, with somewhat fewer lines, remains selected.
229 If you answer @kbd{no} or quit with @kbd{C-g} when asked to confirm, you
230 return immediately to Dired, with the deletion flags still present in
231 the buffer, and no files actually deleted.
233 @cindex recursive deletion
234 @vindex dired-recursive-deletes
235 You can delete empty directories just like other files, but normally
236 Dired cannot delete directories that are nonempty. If the variable
237 @code{dired-recursive-deletes} is non-@code{nil}, then Dired can
238 delete nonempty directories including all their contents. That can
240 Even if you have set @code{dired-recursive-deletes} to @code{nil},
241 you might want sometimes to delete recursively directories
242 without being asked for confirmation for all of them. This is handy
243 when you have marked many directories for deletion and you are very
244 sure that all of them can safely be deleted. For every nonempty
245 directory you are asked for confirmation; if you answer @code{all},
246 then all the remaining directories will be deleted without more
249 @vindex delete-by-moving-to-trash@r{, and Dired}
250 If you change the variable @code{delete-by-moving-to-trash} to
251 @code{t}, the above deletion commands will move the affected files or
252 directories into the operating system's Trash, instead of deleting
253 them outright. @xref{Misc File Ops}.
255 @node Flagging Many Files
256 @section Flagging Many Files at Once
257 @cindex flagging many files for deletion (in Dired)
259 The @kbd{#}, @kbd{~}, @kbd{.}, @kbd{% &}, and @kbd{% d} commands
260 flag many files for deletion, based on their file names:
264 Flag all auto-save files (files whose names start and end with @samp{#})
265 for deletion (@pxref{Auto Save}).
268 Flag all backup files (files whose names end with @samp{~}) for deletion
271 @item .@: @r{(Period)}
272 Flag excess numeric backup files for deletion. The oldest and newest
273 few backup files of any one file are exempt; the middle ones are
277 Flag for deletion all files with certain kinds of names which suggest
278 you could easily create those files again.
280 @item % d @var{regexp} @key{RET}
281 Flag for deletion all files whose names match the regular expression
285 @kindex # @r{(Dired)}
286 @findex dired-flag-auto-save-files
287 @cindex deleting auto-save files
288 @kbd{#} (@code{dired-flag-auto-save-files}) flags all files whose
289 names look like auto-save files---that is, files whose names begin and
290 end with @samp{#}. @xref{Auto Save}.
292 @kindex ~ @r{(Dired)}
293 @findex dired-flag-backup-files
294 @kbd{~} (@code{dired-flag-backup-files}) flags all files whose names
295 say they are backup files---that is, files whose names end in
296 @samp{~}. @xref{Backup}.
298 @kindex . @r{(Dired)}
299 @vindex dired-kept-versions
300 @findex dired-clean-directory
301 @kbd{.} (period, @code{dired-clean-directory}) flags just some of
302 the backup files for deletion: all but the oldest few and newest few
303 backups of any one file. Normally, the number of newest versions kept
304 for each file is given by the variable @code{dired-kept-versions}
305 (@emph{not} @code{kept-new-versions}; that applies only when saving).
306 The number of oldest versions to keep is given by the variable
307 @code{kept-old-versions}.
309 Period with a positive numeric argument, as in @kbd{C-u 3 .},
310 specifies the number of newest versions to keep, overriding
311 @code{dired-kept-versions}. A negative numeric argument overrides
312 @code{kept-old-versions}, using minus the value of the argument to
313 specify the number of oldest versions of each file to keep.
315 @kindex % & @r{(Dired)}
316 @findex dired-flag-garbage-files
317 @vindex dired-garbage-files-regexp
318 @cindex deleting some backup files
319 @kbd{% &} (@code{dired-flag-garbage-files}) flags files whose names
320 match the regular expression specified by the variable
321 @code{dired-garbage-files-regexp}. By default, this matches certain
322 files produced by @TeX{}, @samp{.bak} files, and the @samp{.orig} and
323 @samp{.rej} files produced by @code{patch}.
325 @findex dired-flag-files-regexp
326 @kindex % d @r{(Dired)}
327 @kbd{% d} flags all files whose names match a specified regular
328 expression (@code{dired-flag-files-regexp}). Only the non-directory
329 part of the file name is used in matching. You can use @samp{^} and
330 @samp{$} to anchor matches. You can exclude certain subdirectories
331 from marking by hiding them while you use @kbd{% d}. @xref{Hiding
335 @section Visiting Files in Dired
337 There are several Dired commands for visiting or examining the files
338 listed in the Dired buffer. All of them apply to the current line's
339 file; if that file is really a directory, these commands invoke Dired on
340 that subdirectory (making a separate Dired buffer).
344 @kindex f @r{(Dired)}
345 @findex dired-find-file
346 Visit the file described on the current line, like typing @kbd{C-x C-f}
347 and supplying that file name (@code{dired-find-file}). @xref{Visiting}.
351 @kindex RET @r{(Dired)}
352 @kindex e @r{(Dired)}
353 Equivalent to @kbd{f}.
355 @ignore @c This command seems too risky to document at all.
357 @kindex a @r{(Dired)}
358 @findex dired-find-alternate-file
359 Like @kbd{f}, but replaces the contents of the Dired buffer with
360 that of an alternate file or directory (@code{dired-find-alternate-file}).
364 @kindex o @r{(Dired)}
365 @findex dired-find-file-other-window
366 Like @kbd{f}, but uses another window to display the file's buffer
367 (@code{dired-find-file-other-window}). The Dired buffer remains visible
368 in the first window. This is like using @kbd{C-x 4 C-f} to visit the
369 file. @xref{Windows}.
372 @kindex C-o @r{(Dired)}
373 @findex dired-display-file
374 Visit the file described on the current line, and display the buffer in
375 another window, but do not select that window (@code{dired-display-file}).
379 @findex dired-mouse-find-file-other-window
380 Visit the file whose name you clicked on
381 (@code{dired-mouse-find-file-other-window}). This uses another window
382 to display the file, like the @kbd{o} command.
385 @kindex v @r{(Dired)}
386 @findex dired-view-file
387 View the file described on the current line, with View mode
388 (@code{dired-view-file}). View mode provides convenient commands to
389 navigate the buffer but forbids changing it; @xref{View Mode}.
392 @kindex ^ @r{(Dired)}
393 @findex dired-up-directory
394 Visit the parent directory of the current directory
395 (@code{dired-up-directory}). This is equivalent to moving to the line
396 for @file{..} and typing @kbd{f} there.
400 @section Dired Marks vs.@: Flags
402 @cindex marking many files (in Dired)
403 Instead of flagging a file with @samp{D}, you can @dfn{mark} the
404 file with some other character (usually @samp{*}). Most Dired
405 commands to operate on files use the files marked with @samp{*}. The
406 only command that operates on flagged files is @kbd{x}, which deletes
409 Here are some commands for marking with @samp{*}, for unmarking, and
410 for operating on marks. (@xref{Dired Deletion}, for commands to flag
416 @kindex m @r{(Dired)}
417 @kindex * m @r{(Dired)}
419 Mark the current file with @samp{*} (@code{dired-mark}). If the
420 region is active, mark all files in the region instead; otherwise, if
421 a numeric argument @var{n} is supplied, mark the next @var{n} files
422 instead, starting with the current file (if @var{n} is negative, mark
423 the previous @minus{}@var{n} files).
426 @kindex * * @r{(Dired)}
427 @findex dired-mark-executables
428 @cindex marking executable files (in Dired)
429 Mark all executable files with @samp{*}
430 (@code{dired-mark-executables}). With a numeric argument, unmark all
434 @kindex * @@ @r{(Dired)}
435 @findex dired-mark-symlinks
436 @cindex marking symbolic links (in Dired)
437 Mark all symbolic links with @samp{*} (@code{dired-mark-symlinks}).
438 With a numeric argument, unmark all those files.
441 @kindex * / @r{(Dired)}
442 @findex dired-mark-directories
443 @cindex marking subdirectories (in Dired)
444 Mark with @samp{*} all files which are directories, except for
445 @file{.} and @file{..} (@code{dired-mark-directories}). With a numeric
446 argument, unmark all those files.
449 @kindex * s @r{(Dired)}
450 @findex dired-mark-subdir-files
451 Mark all the files in the current subdirectory, aside from @file{.}
452 and @file{..} (@code{dired-mark-subdir-files}).
456 @kindex u @r{(Dired)}
457 @kindex * u @r{(Dired)}
459 Remove any mark on this line (@code{dired-unmark}). If the region is
460 active, unmark all files in the region instead; otherwise, if a
461 numeric argument @var{n} is supplied, unmark the next @var{n} files
462 instead, starting with the current file (if @var{n} is negative,
463 unmark the previous @minus{}@var{n} files).
467 @kindex * DEL @r{(Dired)}
468 @findex dired-unmark-backward
469 @cindex unmarking files (in Dired)
470 Move point to previous line and remove any mark on that line
471 (@code{dired-unmark-backward}). If the region is active, unmark all
472 files in the region instead; otherwise, if a numeric argument @var{n}
473 is supplied, unmark the @var{n} preceding files instead, starting with
474 the current file (if @var{n} is negative, unmark the next
475 @minus{}@var{n} files).
479 @kindex * ! @r{(Dired)}
480 @kindex U @r{(Dired)}
481 @findex dired-unmark-all-marks
482 Remove all marks from all the files in this Dired buffer
483 (@code{dired-unmark-all-marks}).
485 @item * ? @var{markchar}
487 @kindex * ? @r{(Dired)}
488 @kindex M-DEL @r{(Dired)}
489 @findex dired-unmark-all-files
490 Remove all marks that use the character @var{markchar}
491 (@code{dired-unmark-all-files}). If invoked with @kbd{M-@key{DEL}},
492 the command prompts for @var{markchar}. That @var{markchar} is a
493 single character---do not use @key{RET} to terminate it. See the
494 description of the @kbd{* c} command below, which lets you replace one
495 mark character with another.
497 With a numeric argument, this command queries about each marked file,
498 asking whether to remove its mark. You can answer @kbd{y} meaning yes,
499 @kbd{n} meaning no, or @kbd{!} to remove the marks from the remaining
500 files without asking about them.
504 @findex dired-next-marked-file
505 @kindex * C-n @r{(Dired)}
506 @kindex M-@} @r{(Dired)}
507 Move down to the next marked file (@code{dired-next-marked-file}).
508 A file is ``marked'' if it has any kind of mark.
512 @findex dired-prev-marked-file
513 @kindex * C-p @r{(Dired)}
514 @kindex M-@{ @r{(Dired)}
515 Move up to the previous marked file (@code{dired-prev-marked-file}).
519 @kindex t @r{(Dired)}
520 @kindex * t @r{(Dired)}
521 @findex dired-toggle-marks
522 @cindex toggling marks (in Dired)
523 Toggle all marks (@code{dired-toggle-marks}): files marked with @samp{*}
524 become unmarked, and unmarked files are marked with @samp{*}. Files
525 marked in any other way are not affected.
527 @item * c @var{old-markchar} @var{new-markchar}
528 @kindex * c @r{(Dired)}
529 @findex dired-change-marks
530 Replace all marks that use the character @var{old-markchar} with marks
531 that use the character @var{new-markchar} (@code{dired-change-marks}).
532 This command is the primary way to create or use marks other than
533 @samp{*} or @samp{D}. The arguments are single characters---do not use
534 @key{RET} to terminate them.
536 You can use almost any character as a mark character by means of this
537 command, to distinguish various classes of files. If @var{old-markchar}
538 is a space (@samp{ }), then the command operates on all unmarked files;
539 if @var{new-markchar} is a space, then the command unmarks the files it
542 To illustrate the power of this command, here is how to put @samp{D}
543 flags on all the files that have no marks, while unflagging all those
544 that already have @samp{D} flags:
547 * c D t * c @key{SPC} D * c t @key{SPC}
550 This assumes that no files were already marked with @samp{t}.
552 @item % m @var{regexp} @key{RET}
553 @itemx * % @var{regexp} @key{RET}
554 @findex dired-mark-files-regexp
555 @kindex % m @r{(Dired)}
556 @kindex * % @r{(Dired)}
557 Mark (with @samp{*}) all files whose names match the regular expression
558 @var{regexp} (@code{dired-mark-files-regexp}). This command is like
559 @kbd{% d}, except that it marks files with @samp{*} instead of flagging
562 Only the non-directory part of the file name is used in matching. Use
563 @samp{^} and @samp{$} to anchor matches. You can exclude
564 subdirectories by temporarily hiding them (@pxref{Hiding
567 @item % g @var{regexp} @key{RET}
568 @findex dired-mark-files-containing-regexp
569 @kindex % g @r{(Dired)}
570 @cindex finding files containing regexp matches (in Dired)
571 Mark (with @samp{*}) all files whose @emph{contents} contain a match for
572 the regular expression @var{regexp}
573 (@code{dired-mark-files-containing-regexp}). This command is like
574 @kbd{% m}, except that it searches the file contents instead of the file
575 name. Note that if a file is visited in an Emacs buffer,
576 and @code{dired-always-read-filesystem} is @code{nil} (the default), this
577 command will look in the buffer without revisiting the file, so the results
578 might be inconsistent with the file on disk if its contents have changed
579 since it was last visited. If you don't want this, you may wish to
580 revert the files you have visited in your buffers, or to turn on
581 the @code{auto-revert} mode in those buffers, before invoking this
582 command. @xref{Reverting}. If you prefer that this command always revisit
583 the file, without having to revert the file or enable @code{auto-revert}
584 mode, you might want to set @code{dired-always-read-filesystem} to non-@code{nil}.
589 @kindex C-_ @r{(Dired)}
591 Undo changes in the Dired buffer, such as adding or removing
592 marks (@code{dired-undo}). @emph{This command does not revert the
593 actual file operations, nor recover lost files!} It just undoes
594 changes in the buffer itself.
596 In some cases, using this after commands that operate on files can
597 cause trouble. For example, after renaming one or more files,
598 @code{dired-undo} restores the original names in the Dired buffer,
599 which gets the Dired buffer out of sync with the actual contents of
603 @node Operating on Files
604 @section Operating on Files
605 @cindex operating on files in Dired
607 This section describes the basic Dired commands to operate on one file
608 or several files. All of these commands are capital letters; all of
609 them use the minibuffer, either to read an argument or to ask for
610 confirmation, before they act. All of them let you specify the
611 files to manipulate in these ways:
615 If you give the command a numeric prefix argument @var{n}, it operates
616 on the next @var{n} files, starting with the current file. (If @var{n}
617 is negative, the command operates on the @minus{}@var{n} files preceding
621 Otherwise, if some files are marked with @samp{*}, the command operates
625 Otherwise, the command operates on the current file only.
629 Certain other Dired commands, such as @kbd{!} and the @samp{%}
630 commands, use the same conventions to decide which files to work on.
632 @vindex dired-dwim-target
633 @cindex two directories (in Dired)
634 Commands which ask for a destination directory, such as those which
635 copy and rename files or create links for them, try to guess the default
636 target directory for the operation. Normally, they suggest the Dired
637 buffer's default directory, but if the variable @code{dired-dwim-target}
638 is non-@code{nil}, and if there is another Dired buffer displayed in the
639 next window, that other buffer's directory is suggested instead.
641 Here are the file-manipulating Dired commands that operate on files.
644 @findex dired-do-copy
645 @kindex C @r{(Dired)}
646 @cindex copying files (in Dired)
647 @item C @var{new} @key{RET}
648 Copy the specified files (@code{dired-do-copy}). The argument @var{new}
649 is the directory to copy into, or (if copying a single file) the new
650 name. This is like the shell command @code{cp}.
652 @vindex dired-create-destination-dirs
653 The option @code{dired-create-destination-dirs} controls whether Dired
654 should create non-existent directories in the destination while
655 copying/renaming files. The default value @code{nil} means Dired
656 never creates such missing directories; the value @code{always},
657 means Dired automatically creates them; the value @code{ask}
658 means Dired asks you for confirmation before creating them.
660 @vindex dired-copy-preserve-time
661 If @code{dired-copy-preserve-time} is non-@code{nil}, then copying
662 with this command preserves the modification time of the old file in
663 the copy, like @samp{cp -p}.
665 @vindex dired-recursive-copies
666 @cindex recursive copying
667 The variable @code{dired-recursive-copies} controls whether to copy
668 directories recursively (like @samp{cp -r}). The default is
669 @code{top}, which means to ask before recursively copying a directory.
672 @findex dired-do-delete
673 @kindex D @r{(Dired)}
674 Delete the specified files (@code{dired-do-delete}). This is like the
675 shell command @code{rm}.
677 Like the other commands in this section, this command operates on the
678 @emph{marked} files, or the next @var{n} files. By contrast, @kbd{x}
679 (@code{dired-do-flagged-delete}) deletes all @dfn{flagged} files.
681 @findex dired-do-rename
682 @kindex R @r{(Dired)}
683 @cindex renaming files (in Dired)
684 @cindex moving files (in Dired)
685 @item R @var{new} @key{RET}
686 Rename the specified files (@code{dired-do-rename}). If you rename a
687 single file, the argument @var{new} is the new name of the file. If
688 you rename several files, the argument @var{new} is the directory into
689 which to move the files (this is like the shell command @command{mv}).
691 The option @code{dired-create-destination-dirs} controls whether Dired
692 should create non-existent directories in @var{new}.
694 Dired automatically changes the visited file name of buffers associated
695 with renamed files so that they refer to the new names.
697 @findex dired-do-hardlink
698 @kindex H @r{(Dired)}
699 @cindex hard links (in Dired)
700 @item H @var{new} @key{RET}
701 Make hard links to the specified files (@code{dired-do-hardlink}).
702 This is like the shell command @command{ln}. The argument @var{new} is
703 the directory to make the links in, or (if making just one link) the
704 name to give the link.
706 @findex dired-do-symlink
707 @kindex S @r{(Dired)}
708 @cindex symbolic links (creation in Dired)
709 @item S @var{new} @key{RET}
710 Make symbolic links to the specified files (@code{dired-do-symlink}).
711 This is like @samp{ln -s}. The argument @var{new} is the directory to
712 make the links in, or (if making just one link) the name to give the
715 @findex dired-do-chmod
716 @kindex M @r{(Dired)}
717 @cindex changing file permissions (in Dired)
718 @item M @var{modespec} @key{RET}
719 Change the mode (also called @dfn{permission bits}) of the specified
720 files (@code{dired-do-chmod}). @var{modespec} can be in octal or
721 symbolic notation, like arguments handled by the @command{chmod}
724 @findex dired-do-chgrp
725 @kindex G @r{(Dired)}
726 @cindex changing file group (in Dired)
727 @item G @var{newgroup} @key{RET}
728 Change the group of the specified files to @var{newgroup}
729 (@code{dired-do-chgrp}).
731 @findex dired-do-chown
732 @kindex O @r{(Dired)}
733 @cindex changing file owner (in Dired)
734 @item O @var{newowner} @key{RET}
735 Change the owner of the specified files to @var{newowner}
736 (@code{dired-do-chown}). (On most systems, only the superuser can do
739 @vindex dired-chown-program
740 The variable @code{dired-chown-program} specifies the name of the
741 program to use to do the work (different systems put @command{chown}
742 in different places).
744 @findex dired-do-touch
745 @kindex T @r{(Dired)}
746 @cindex changing file time (in Dired)
747 @item T @var{timestamp} @key{RET}
748 Touch the specified files (@code{dired-do-touch}). This means
749 updating their modification times to the present time. This is like
750 the shell command @code{touch}.
752 @findex dired-do-print
753 @kindex P @r{(Dired)}
754 @cindex printing files (in Dired)
755 @item P @var{command} @key{RET}
756 Print the specified files (@code{dired-do-print}). You must specify the
757 command to print them with, but the minibuffer starts out with a
758 suitable guess made using the variables @code{lpr-command} and
759 @code{lpr-switches} (the same variables that @code{lpr-buffer} uses;
762 @findex dired-do-compress
763 @kindex Z @r{(Dired)}
764 @cindex compressing files (in Dired)
766 Compress the specified files (@code{dired-do-compress}). If the file
767 appears to be a compressed file already, uncompress it instead. Each
768 marked file is compressed into its own archive.
770 @findex dired-do-compress-to
771 @kindex c @r{(Dired)}
773 Compress the specified files (@code{dired-do-compress-to}) into a
774 single archive anywhere on the file system. The compression algorithm
775 is determined by the extension of the archive, see
776 @code{dired-compress-files-alist}.
778 @findex epa-dired-do-decrypt
779 @kindex :d @r{(Dired)}
780 @cindex decrypting files (in Dired)
782 Decrypt the specified files (@code{epa-dired-do-decrypt}).
783 @xref{Dired integration,,, epa, EasyPG Assistant User's Manual}.
785 @findex epa-dired-do-verify
786 @kindex :v @r{(Dired)}
787 @cindex verifying digital signatures on files (in Dired)
789 Verify digital signatures on the specified files (@code{epa-dired-do-verify}).
790 @xref{Dired integration,,, epa, EasyPG Assistant User's Manual}.
792 @findex epa-dired-do-sign
793 @kindex :s @r{(Dired)}
794 @cindex signing files (in Dired)
796 Digitally sign the specified files (@code{epa-dired-do-sign}).
797 @xref{Dired integration,,, epa, EasyPG Assistant User's Manual}.
799 @findex epa-dired-do-encrypt
800 @kindex :e @r{(Dired)}
801 @cindex encrypting files (in Dired)
803 Encrypt the specified files (@code{epa-dired-do-encrypt}).
804 @xref{Dired integration,,, epa, EasyPG Assistant User's Manual}.
806 @findex dired-do-load
807 @kindex L @r{(Dired)}
808 @cindex loading several files (in Dired)
810 Load the specified Emacs Lisp files (@code{dired-do-load}).
811 @xref{Lisp Libraries}.
813 @findex dired-do-byte-compile
814 @kindex B @r{(Dired)}
815 @cindex byte-compiling several files (in Dired)
817 Byte compile the specified Emacs Lisp files
818 (@code{dired-do-byte-compile}). @xref{Byte Compilation,, Byte
819 Compilation, elisp, The Emacs Lisp Reference Manual}.
821 @kindex A @r{(Dired)}
822 @findex dired-do-find-regexp
823 @cindex search multiple files (in Dired)
824 @item A @var{regexp} @key{RET}
825 Search all the specified files for the regular expression @var{regexp}
826 (@code{dired-do-find-regexp}).
828 This command is a variant of @code{xref-find-references}
829 (@pxref{Identifier Search}), it displays the @file{*xref*} buffer,
830 where you can navigate between matches and display them as needed
831 using the commands described in @ref{Xref Commands}.
833 @vindex grep-find-ignored-files @r{(Dired)}
834 @vindex grep-find-ignored-directories @r{(Dired)}
835 If any of the marked files are directories, then this command searches
836 all of the files in those directories, and any of their
837 subdirectories, recursively, except files whose names match
838 @code{grep-find-ignored-files} and subdirectories whose names match
839 @code{grep-find-ignored-directories}.
841 @kindex Q @r{(Dired)}
842 @findex dired-do-find-regexp-and-replace
843 @cindex search and replace in multiple files (in Dired)
844 @item Q @var{regexp} @key{RET} @var{to} @key{RET}
845 Perform @code{query-replace-regexp} on each of the specified files,
846 replacing matches for @var{regexp} with the string
847 @var{to} (@code{dired-do-find-regexp-and-replace}).
849 This command is a variant of @code{xref-query-replace-in-results}. It
850 presents an @file{*xref*} buffer that lists all the matches of @var{regexp},
851 and you can use the special commands in that buffer (@pxref{Xref
852 Commands}). In particular, if you exit the query replace loop, you
853 can use @kbd{r} in that buffer to replace more matches.
854 @xref{Identifier Search}.
856 Like with @code{dired-do-find-regexp}, if any of the marked files are
857 directories, this command performs replacements in all of the files in
858 those directories, and in any of their subdirectories, recursively,
859 except for files whose names match @code{grep-find-ignored-files} and
860 subdirectories whose names match @code{grep-find-ignored-directories}.
863 @node Shell Commands in Dired
864 @section Shell Commands in Dired
865 @cindex shell commands, Dired
867 @findex dired-do-shell-command
868 @kindex ! @r{(Dired)}
869 @kindex X @r{(Dired)}
870 The Dired command @kbd{!} (@code{dired-do-shell-command}) reads a
871 shell command string in the minibuffer, and runs that shell command on
872 one or more files. The files that the shell command operates on are
873 determined in the usual way for Dired commands (@pxref{Operating on
874 Files}). The command @kbd{X} is a synonym for @kbd{!}.
876 The command @kbd{&} (@code{dired-do-async-shell-command}) does the
877 same, except that it runs the shell command asynchronously. (You can
878 also do this with @kbd{!}, by appending a @samp{&} character to the
879 end of the shell command.) When the command operates on more than one
880 file, it runs multiple parallel copies of the specified shell command,
881 one for each file. As an exception, if the specified shell command
882 ends in @samp{;} or @samp{;&}, the shell command is run in the
883 background on each file sequentially; Emacs waits for each invoked
884 shell command to terminate before running the next one.
886 For both @kbd{!} and @kbd{&}, the working directory for the shell
887 command is the top-level directory of the Dired buffer.
889 If you tell @kbd{!} or @kbd{&} to operate on more than one file, the
890 shell command string determines how those files are passed to the
895 If you use @samp{*} surrounded by whitespace in the command string,
896 then the command runs just once, with the list of file names
897 substituted for the @samp{*}. The order of file names is the order of
898 appearance in the Dired buffer.
900 Thus, @kbd{! tar cf foo.tar * @key{RET}} runs @code{tar} on the entire
901 list of file names, putting them into one tar file @file{foo.tar}.
903 If you want to use @samp{*} as a shell wildcard with whitespace around
904 it, write @samp{*""}. In the shell, this is equivalent to @samp{*};
905 but since the @samp{*} is not surrounded by whitespace, Dired does not
909 Otherwise, if the command string contains @samp{?} surrounded by
910 whitespace or @samp{`?`}, Emacs runs the shell command once
911 @emph{for each file}, substituting the current file name for @samp{?}
912 and @samp{`?`} each time. You can use both @samp{?} or @samp{`?`} more
913 than once in the command; the same file name replaces each occurrence.
914 If you mix them with @samp{*} the command signals an error.
917 If the command string contains neither @samp{*} nor @samp{?} nor @samp{`?`},
918 Emacs runs the shell command once for each file, adding the file name at the
919 end. For example, @kbd{! uudecode @key{RET}} runs @code{uudecode} on
923 To iterate over the file names in a more complicated fashion, you might
924 prefer to use an explicit shell loop. For example, here is how to uuencode
925 each file, making the output file name by appending @samp{.uu} to the input
929 for file in * ; do uuencode "$file" "$file" >"$file".uu; done
932 The same example with @samp{`?`} notation:
934 uuencode ? ? > `?`.uu
937 The @kbd{!} and @kbd{&} commands do not attempt to update the Dired
938 buffer to show new or modified files, because they don't know what
939 files will be changed. Use the @kbd{g} command to update the Dired
940 buffer (@pxref{Dired Updating}).
942 @xref{Single Shell}, for information about running shell commands
945 @node Transforming File Names
946 @section Transforming File Names in Dired
948 This section describes Dired commands which alter file names in a
949 systematic way. Each command operates on some or all of the marked
950 files, using a new name made by transforming the existing name.
952 Like the basic Dired file-manipulation commands (@pxref{Operating on
953 Files}), the commands described here operate either on the next
954 @var{n} files, or on all files marked with @samp{*}, or on the current
955 file. (To mark files, use the commands described in @ref{Marks vs
958 All of the commands described in this section work
959 @emph{interactively}: they ask you to confirm the operation for each
960 candidate file. Thus, you can select more files than you actually
961 need to operate on (e.g., with a regexp that matches many files), and
962 then filter the selected names by typing @kbd{y} or @kbd{n} when the
963 command prompts for confirmation.
967 @kindex % u @r{(Dired)}
968 @cindex upcase file names
970 Rename each of the selected files to an upper-case name
971 (@code{dired-upcase}). If the old file names are @file{Foo}
972 and @file{bar}, the new names are @file{FOO} and @file{BAR}.
975 @findex dired-downcase
976 @kindex % l @r{(Dired)}
977 @cindex downcase file names
978 Rename each of the selected files to a lower-case name
979 (@code{dired-downcase}). If the old file names are @file{Foo} and
980 @file{bar}, the new names are @file{foo} and @file{bar}.
982 @item % R @var{from} @key{RET} @var{to} @key{RET}
983 @kindex % R @r{(Dired)}
984 @findex dired-do-rename-regexp
985 @itemx % C @var{from} @key{RET} @var{to} @key{RET}
986 @kindex % C @r{(Dired)}
987 @findex dired-do-copy-regexp
988 @itemx % H @var{from} @key{RET} @var{to} @key{RET}
989 @kindex % H @r{(Dired)}
990 @findex dired-do-hardlink-regexp
991 @itemx % S @var{from} @key{RET} @var{to} @key{RET}
992 @kindex % S @r{(Dired)}
993 @findex dired-do-symlink-regexp
994 These four commands rename, copy, make hard links and make soft links,
995 in each case computing the new name by regular-expression substitution
996 from the name of the old file.
999 The four regular-expression substitution commands effectively
1000 perform a search-and-replace on the selected file names. They read
1001 two arguments: a regular expression @var{from}, and a substitution
1002 pattern @var{to}; they match each old file name against
1003 @var{from}, and then replace the matching part with @var{to}. You can
1004 use @samp{\&} and @samp{\@var{digit}} in @var{to} to refer to all or
1005 part of what the pattern matched in the old file name, as in
1006 @code{replace-regexp} (@pxref{Regexp Replace}). If the regular
1007 expression matches more than once in a file name, only the first match
1010 For example, @kbd{% R ^.*$ @key{RET} x-\& @key{RET}} renames each
1011 selected file by prepending @samp{x-} to its name. The inverse of this,
1012 removing @samp{x-} from the front of each file name, is also possible:
1013 one method is @kbd{% R ^x-\(.*\)$ @key{RET} \1 @key{RET}}; another is
1014 @kbd{% R ^x- @key{RET} @key{RET}}. (Use @samp{^} and @samp{$} to anchor
1015 matches that should span the whole file name.)
1017 Normally, the replacement process does not consider the files'
1018 directory names; it operates on the file name within the directory. If
1019 you specify a numeric argument of zero, then replacement affects the
1020 entire absolute file name including directory name. (A non-zero
1021 argument specifies the number of files to operate on.)
1023 You may want to select the set of files to operate on using the same
1024 regexp @var{from} that you will use to operate on them. To do this,
1025 mark those files with @kbd{% m @var{from} @key{RET}}, then use the
1026 same regular expression in the command to operate on the files. To
1027 make this more convenient, the @kbd{%} commands to operate on files
1028 use the last regular expression specified in any @kbd{%} command as a
1031 @node Comparison in Dired
1032 @section File Comparison with Dired
1033 @cindex file comparison (in Dired)
1034 @cindex compare files (in Dired)
1037 @kindex = @r{(Dired)}
1038 The @kbd{=} (@code{dired-diff}) command compares the current file
1039 (the file at point) with another file (read using the minibuffer)
1040 using the @command{diff} program. The file specified with the
1041 minibuffer is the first argument of @command{diff}, and file at point
1042 is the second argument. The output of the @command{diff} program is
1043 shown in a buffer using Diff mode (@pxref{Comparing Files}).
1045 If the region is active, the default for the file read using the
1046 minibuffer is the file at the mark (i.e., the ordinary Emacs mark,
1047 not a Dired mark; @pxref{Setting Mark}). Otherwise, if the file at
1048 point has a backup file (@pxref{Backup}), that is the default.
1050 @node Subdirectories in Dired
1051 @section Subdirectories in Dired
1052 @cindex subdirectories in Dired
1053 @cindex expanding subdirectories in Dired
1055 A Dired buffer usually displays just one directory, but you can
1056 optionally include its subdirectories as well.
1058 The simplest way to include multiple directories in one Dired buffer is
1059 to specify the options @samp{-lR} for running @command{ls}. (If you give a
1060 numeric argument when you run Dired, then you can specify these options
1061 in the minibuffer.) That produces a recursive directory listing showing
1062 all subdirectories at all levels.
1064 More often, you will want to show only specific subdirectories. You
1065 can do this with @kbd{i} (@code{dired-maybe-insert-subdir}):
1068 @findex dired-maybe-insert-subdir
1069 @kindex i @r{(Dired)}
1071 @cindex inserted subdirectory (Dired)
1072 @cindex in-situ subdirectory (Dired)
1073 Insert the contents of a subdirectory later in the buffer.
1077 If you use this command on a line that describes a file which is a
1078 directory, it inserts the contents of that directory into the same
1079 Dired buffer, and moves there. Inserted subdirectory contents follow
1080 the top-level directory of the Dired buffer, just as they do in
1081 @samp{ls -lR} output.
1083 If the subdirectory's contents are already present in the buffer,
1084 the @kbd{i} command just moves to it.
1086 In either case, @kbd{i} sets the Emacs mark before moving, so
1087 @kbd{C-u C-@key{SPC}} returns to your previous position in the Dired
1088 buffer (@pxref{Setting Mark}). You can also use @samp{^} to return to
1089 the parent directory in the same Dired buffer (@pxref{Dired
1092 Use the @kbd{l} command (@code{dired-do-redisplay}) to update the
1093 subdirectory's contents, and use @kbd{C-u k} on the subdirectory
1094 header line to remove the subdirectory listing (@pxref{Dired
1095 Updating}). You can also hide and show inserted subdirectories
1096 (@pxref{Hiding Subdirectories}).
1099 @include dired-xtra.texi
1102 @node Subdirectory Motion
1103 @section Moving Over Subdirectories
1105 When a Dired buffer lists subdirectories, you can use the page motion
1106 commands @kbd{C-x [} and @kbd{C-x ]} to move by entire directories
1109 @cindex header line (Dired)
1110 @cindex directory header lines
1111 The following commands move across, up and down in the tree of
1112 directories within one Dired buffer. They move to @dfn{directory header
1113 lines}, which are the lines that give a directory's name, at the
1114 beginning of the directory's contents.
1117 @findex dired-next-subdir
1118 @kindex C-M-n @r{(Dired)}
1120 Go to next subdirectory header line, regardless of level
1121 (@code{dired-next-subdir}).
1123 @findex dired-prev-subdir
1124 @kindex C-M-p @r{(Dired)}
1126 Go to previous subdirectory header line, regardless of level
1127 (@code{dired-prev-subdir}).
1129 @findex dired-tree-up
1130 @kindex C-M-u @r{(Dired)}
1132 Go up to the parent directory's header line (@code{dired-tree-up}).
1134 @findex dired-tree-down
1135 @kindex C-M-d @r{(Dired)}
1137 Go down in the directory tree, to the first subdirectory's header line
1138 (@code{dired-tree-down}).
1140 @findex dired-prev-dirline
1141 @kindex < @r{(Dired)}
1143 Move up to the previous directory-file line (@code{dired-prev-dirline}).
1144 These lines are the ones that describe a directory as a file in its
1147 @findex dired-next-dirline
1148 @kindex > @r{(Dired)}
1150 Move down to the next directory-file line (@code{dired-next-dirline}).
1153 @node Hiding Subdirectories
1154 @section Hiding Subdirectories
1155 @cindex hiding subdirectories (Dired)
1156 @cindex showing hidden subdirectories (Dired)
1158 @dfn{Hiding} a subdirectory means to make it invisible, except for its
1163 @findex dired-hide-subdir
1164 @kindex $ @r{(Dired)}
1165 Hide or show the subdirectory that point is in, and move point to the
1166 next subdirectory (@code{dired-hide-subdir}). This is a toggle. A
1167 numeric argument serves as a repeat count.
1170 @findex dired-hide-all
1171 @kindex M-$ @r{(Dired)}
1172 Hide all subdirectories in this Dired buffer, leaving only their header
1173 lines (@code{dired-hide-all}). Or, if any subdirectory is currently
1174 hidden, make all subdirectories visible again. You can use this command
1175 to get an overview in very deep directory trees or to move quickly to
1176 subdirectories far away.
1179 Ordinary Dired commands never consider files inside a hidden
1180 subdirectory. For example, the commands to operate on marked files
1181 ignore files in hidden directories even if they are marked. Thus you
1182 can use hiding to temporarily exclude subdirectories from operations
1183 without having to remove the Dired marks on files in those
1186 @xref{Subdirectories in Dired}, for how to insert a subdirectory
1187 listing, and @pxref{Dired Updating} for how delete it.
1189 @node Dired Updating
1190 @section Updating the Dired Buffer
1191 @cindex updating Dired buffer
1192 @cindex refreshing displayed files
1194 This section describes commands to update the Dired buffer to reflect
1195 outside (non-Dired) changes in the directories and files, and to delete
1196 part of the Dired buffer.
1200 Update the entire contents of the Dired buffer (@code{revert-buffer}).
1203 Update the specified files (@code{dired-do-redisplay}). You specify the
1204 files for @kbd{l} in the same way as for file operations.
1207 Delete the specified @emph{file lines}---not the files, just the lines
1208 (@code{dired-do-kill-lines}).
1211 Toggle between alphabetical order and date/time order
1212 (@code{dired-sort-toggle-or-edit}).
1214 @item C-u s @var{switches} @key{RET}
1215 Refresh the Dired buffer using @var{switches} as
1216 @code{dired-listing-switches}.
1219 @kindex g @r{(Dired)}
1220 @findex revert-buffer @r{(Dired)}
1221 Type @kbd{g} (@code{revert-buffer}) to update the contents of the
1222 Dired buffer, based on changes in the files and directories listed.
1223 This preserves all marks except for those on files that have vanished.
1224 Hidden subdirectories are updated but remain hidden.
1226 @kindex l @r{(Dired)}
1227 @findex dired-do-redisplay
1228 To update only some of the files, type @kbd{l}
1229 (@code{dired-do-redisplay}). Like the Dired file-operating commands,
1230 this command operates on the next @var{n} files (or previous
1231 @minus{}@var{n} files), or on the marked files if any, or on the
1232 current file. Updating the files means reading their current status,
1233 then updating their lines in the buffer to indicate that status.
1235 If you use @kbd{l} on a subdirectory header line, it updates the
1236 contents of the corresponding subdirectory.
1238 @vindex dired-auto-revert-buffer
1239 If you use @kbd{C-x d} or some other Dired command to visit a
1240 directory that is already being shown in a Dired buffer, Dired
1241 switches to that buffer but does not update it. If the buffer is not
1242 up-to-date, Dired displays a warning telling you to type @key{g} to
1243 update it. You can also tell Emacs to revert each Dired buffer
1244 automatically when you revisit it, by setting the variable
1245 @code{dired-auto-revert-buffer} to a non-@code{nil} value.
1247 @kindex k @r{(Dired)}
1248 @findex dired-do-kill-lines
1249 To delete @emph{file lines} from the buffer---without actually
1250 deleting the files---type @kbd{k} (@code{dired-do-kill-lines}). Like
1251 the file-operating commands, this command operates on the next @var{n}
1252 files, or on the marked files if any. However, it does not operate on
1253 the current file, since otherwise mistyping @kbd{k} could be annoying.
1255 If you use @kbd{k} to kill the line for a directory file which you
1256 had inserted in the Dired buffer as a subdirectory
1257 (@pxref{Subdirectories in Dired}), it removes the subdirectory listing
1258 as well. Typing @kbd{C-u k} on the header line for a subdirectory
1259 also removes the subdirectory line from the Dired buffer.
1261 The @kbd{g} command brings back any individual lines that you have
1262 killed in this way, but not subdirectories---you must use @kbd{i} to
1263 reinsert a subdirectory.
1265 @cindex Dired sorting
1266 @cindex sorting Dired buffer
1267 @kindex s @r{(Dired)}
1268 @findex dired-sort-toggle-or-edit
1269 The files in a Dired buffers are normally listed in alphabetical order
1270 by file names. Alternatively Dired can sort them by date/time. The
1271 Dired command @kbd{s} (@code{dired-sort-toggle-or-edit}) switches
1272 between these two sorting modes. The mode line in a Dired buffer
1273 indicates which way it is currently sorted---by name, or by date.
1275 @kbd{C-u s @var{switches} @key{RET}} lets you specify a new value for
1276 @code{dired-listing-switches}.
1278 @node Dired and Find
1279 @section Dired and @code{find}
1280 @cindex @code{find} and Dired
1282 You can select a set of files for display in a Dired buffer more
1283 flexibly by using the @command{find} utility to choose the files.
1285 @findex find-name-dired
1286 To search for files with names matching a wildcard pattern use
1287 @kbd{M-x find-name-dired}. It reads arguments @var{directory} and
1288 @var{pattern}, and chooses all the files in @var{directory} or its
1289 subdirectories whose individual names match @var{pattern}.
1291 The files thus chosen are displayed in a Dired buffer, in which the
1292 ordinary Dired commands are available.
1294 @findex find-grep-dired
1295 If you want to test the contents of files, rather than their names,
1296 use @kbd{M-x find-grep-dired}. This command reads two minibuffer
1297 arguments, @var{directory} and @var{regexp}; it chooses all the files
1298 in @var{directory} or its subdirectories that contain a match for
1299 @var{regexp}. It works by running the programs @command{find} and
1300 @command{grep}. See also @kbd{M-x grep-find}, in @ref{Grep
1301 Searching}. Remember to write the regular expression for
1302 @command{grep}, not for Emacs. (An alternative method of showing
1303 files whose contents match a given regexp is the @kbd{% g
1304 @var{regexp}} command, see @ref{Marks vs Flags}.)
1307 The most general command in this series is @kbd{M-x find-dired},
1308 which lets you specify any condition that @command{find} can test. It
1309 takes two minibuffer arguments, @var{directory} and @var{find-args};
1310 it runs @command{find} in @var{directory}, passing @var{find-args} to
1311 tell @command{find} what condition to test. To use this command, you
1312 need to know how to use @command{find}.
1314 @vindex find-ls-option
1315 The format of listing produced by these commands is controlled by
1316 the variable @code{find-ls-option}. This is a pair of options; the
1317 first specifying how to call @command{find} to produce the file listing,
1318 and the second telling Dired to parse the output.
1321 @findex locate-with-filter
1322 @cindex file database (locate)
1323 @vindex locate-command
1324 The command @kbd{M-x locate} provides a similar interface to the
1325 @command{locate} program. @kbd{M-x locate-with-filter} is similar, but
1326 keeps only files whose names match a given regular expression.
1328 These buffers don't work entirely like ordinary Dired buffers: file
1329 operations work, but do not always automatically update the buffer.
1330 Reverting the buffer with @kbd{g} deletes all inserted subdirectories,
1331 and erases all flags and marks.
1334 @section Editing the Dired Buffer
1337 @findex wdired-change-to-wdired-mode
1338 Wdired is a special mode that allows you to perform file operations
1339 by editing the Dired buffer directly (the ``W'' in ``Wdired'' stands
1340 for ``writable''). To enter Wdired mode, type @kbd{C-x C-q}
1341 (@code{dired-toggle-read-only}) while in a Dired buffer.
1342 Alternatively, use the @samp{Immediate / Edit File Names} menu item.
1344 @findex wdired-finish-edit
1345 While in Wdired mode, you can rename files by editing the file names
1346 displayed in the Dired buffer. All the ordinary Emacs editing
1347 commands, including rectangle operations and @code{query-replace}, are
1348 available for this. Once you are done editing, type @kbd{C-c C-c}
1349 (@code{wdired-finish-edit}). This applies your changes and switches
1350 back to ordinary Dired mode.
1352 Apart from simply renaming files, you can move a file to another
1353 directory by typing in the new file name (either absolute or
1354 relative). To mark a file for deletion, delete the entire file name.
1355 To change the target of a symbolic link, edit the link target name
1356 which appears next to the link name.
1358 If you edit the file names to create a new subdirectory, Wdired will
1359 automatically create these new directories. To inhibit this behavior,
1360 set @code{wdired-create-parent-directories} to @code{nil}.
1362 The rest of the text in the buffer, such as the file sizes and
1363 modification dates, is marked read-only, so you can't edit it.
1364 However, if you set @code{wdired-allow-to-change-permissions} to
1365 @code{t}, you can edit the file permissions. For example, you can
1366 change @samp{-rw-r--r--} to @samp{-rw-rw-rw-} to make a file
1367 world-writable. These changes also take effect when you type @kbd{C-c
1371 @section Viewing Image Thumbnails in Dired
1372 @cindex image-dired mode
1375 Image-Dired is a facility for browsing image files. It provides viewing
1376 the images either as thumbnails or in full size, either inside Emacs
1377 or through an external viewer.
1379 @kindex C-t d @r{(Image-Dired)}
1380 @findex image-dired-display-thumbs
1381 To enter Image-Dired, mark the image files you want to look at in
1382 the Dired buffer, using @kbd{m} as usual. Then type @kbd{C-t d}
1383 (@code{image-dired-display-thumbs}). This creates and switches to a
1384 buffer containing image-dired, corresponding to the marked files.
1386 You can also enter Image-Dired directly by typing @kbd{M-x
1387 image-dired}. This prompts for a directory; specify one that has
1388 image files. This creates thumbnails for all the images in that
1389 directory, and displays them all in the thumbnail buffer. This
1390 takes a long time if the directory contains many image files, and it
1391 asks for confirmation if the number of image files exceeds
1392 @code{image-dired-show-all-from-dir-max-files}.
1394 With point in the thumbnail buffer, you can type @key{RET}
1395 (@code{image-dired-display-thumbnail-original-image}) to display a
1396 sized version of it in another window. This sizes the image to fit
1397 the window. Use the arrow keys to move around in the buffer. For
1398 easy browsing, use @key{SPC}
1399 (@code{image-dired-display-next-thumbnail-original}) to advance and
1400 display the next image. Typing @key{DEL}
1401 (@code{image-dired-display-previous-thumbnail-original}) backs up to
1402 the previous thumbnail and displays that instead.
1404 @vindex image-dired-external-viewer
1405 To view and the image in its original size, either provide a prefix
1406 argument (@kbd{C-u}) before pressing @key{RET}, or type
1407 @kbd{C-@key{RET}} (@code{image-dired-thumbnail-display-external}) to
1408 display the image in an external viewer. You must first configure
1409 @code{image-dired-external-viewer}.
1411 You can delete images through Image-Dired also. Type @kbd{d}
1412 (@code{image-dired-flag-thumb-original-file}) to flag the image file
1413 for deletion in the Dired buffer. You can also delete the thumbnail
1414 image from the thumbnail buffer with @kbd{C-d}
1415 (@code{image-dired-delete-char}).
1417 More advanced features include @dfn{image tags}, which are metadata
1418 used to categorize image files. The tags are stored in a plain text
1419 file configured by @code{image-dired-db-file}.
1421 To tag image files, mark them in the dired buffer (you can also mark
1422 files in Dired from the thumbnail buffer by typing @kbd{m}) and type
1423 @kbd{C-t t} (@code{image-dired-tag-files}). This reads the tag name
1424 in the minibuffer. To mark files having a certain tag, type @kbd{C-t f}
1425 (@code{image-dired-mark-tagged-files}). After marking image files
1426 with a certain tag, you can use @kbd{C-t d} to view them.
1428 You can also tag a file directly from the thumbnail buffer by typing
1429 @kbd{t t} and you can remove a tag by typing @kbd{t r}. There is also
1430 a special tag called ``comment'' for each file (it is not a tag in
1431 the exact same sense as the other tags, it is handled slightly
1432 differently). That is used to enter a comment or description about the
1433 image. You comment a file from the thumbnail buffer by typing
1434 @kbd{c}. You will be prompted for a comment. Type @kbd{C-t c} to add
1435 a comment from Dired (@code{image-dired-dired-comment-files}).
1437 Image-Dired also provides simple image manipulation. In the
1438 thumbnail buffer, type @kbd{L} to rotate the original image 90 degrees
1439 anti clockwise, and @kbd{R} to rotate it 90 degrees clockwise. This
1440 rotation is lossless, and uses an external utility called JpegTRAN.
1442 @node Misc Dired Features
1443 @section Other Dired Features
1445 @kindex + @r{(Dired)}
1446 @findex dired-create-directory
1447 The command @kbd{+} (@code{dired-create-directory}) reads a
1448 directory's name, and creates that directory. It signals an error if
1449 the directory already exists.
1451 @cindex searching multiple files via Dired
1452 @kindex M-s a C-s @r{(Dired)}
1453 @kindex M-s a M-C-s @r{(Dired)}
1454 @findex dired-do-isearch
1455 @findex dired-do-isearch-regexp
1456 The command @kbd{M-s a C-s} (@code{dired-do-isearch}) begins a
1457 multi-file incremental search on the marked files. If a search
1458 fails at the end of a file, typing @kbd{C-s} advances to the next
1459 marked file and repeats the search; at the end of the last marked
1460 file, the search wraps around to the first marked file. The command
1461 @kbd{M-s a M-C-s} (@code{dired-do-isearch-regexp}) does the same with
1462 a regular expression search. @xref{Repeat Isearch}, for information
1463 about search repetition.
1465 @cindex adding to the kill ring in Dired
1466 @kindex w @r{(Dired)}
1467 @findex dired-copy-filename-as-kill
1468 The command @kbd{w} (@code{dired-copy-filename-as-kill}) puts the
1469 names of the marked (or next @var{n}) files into the kill ring, as if
1470 you had killed them with @kbd{C-w}. The names are separated by a
1473 With a zero prefix argument, this uses the absolute file name of
1474 each marked file. With just @kbd{C-u} as the prefix argument, it uses
1475 file names relative to the Dired buffer's default directory. (This
1476 can still contain slashes if in a subdirectory.) As a special case,
1477 if point is on a directory headerline, @kbd{w} gives you the absolute
1478 name of that directory. Any prefix argument or marked files are
1479 ignored in this case.
1481 The main purpose of this command is so that you can yank the file
1482 names into arguments for other Emacs commands. It also displays what
1483 it added to the kill ring, so you can use it to display the list of
1484 currently marked files in the echo area.
1486 @kindex W @r{(Dired)}
1487 @findex browse-url-of-dired-file
1488 If you have an HTML file in the file listing, it can be useful to
1489 view that file with a browser. The @kbd{W}
1490 (@code{browse-url-of-dired-file}) command will use the standard
1491 configured browser to view that file.
1493 @kindex ( @r{(Dired)}
1494 @findex dired-hide-details-mode
1495 @vindex dired-hide-details-hide-symlink-targets
1496 @vindex dired-hide-details-hide-information-lines
1497 @cindex hiding details in Dired
1498 The command @kbd{(} (@code{dired-hide-details-mode}) toggles whether
1499 details, such as ownership or file permissions, are visible in the
1500 current Dired buffer. By default, it also hides the targets of
1501 symbolic links, and all lines other than the header line and
1502 file/directory listings. To change this, customize the options
1503 @code{dired-hide-details-hide-symlink-targets} and
1504 @code{dired-hide-details-hide-information-lines}, respectively.
1506 @cindex Dired and version control
1507 If the directory you are visiting is under version control
1508 (@pxref{Version Control}), then the normal VC diff and log commands
1509 will operate on the selected files.
1511 @findex dired-compare-directories
1512 The command @kbd{M-x dired-compare-directories} is used to compare
1513 the current Dired buffer with another directory. It marks all the files
1514 that differ between the two directories. It puts these marks
1515 in all Dired buffers where these files are listed, which of course includes
1518 The default comparison method (used if you type @key{RET} at the
1519 prompt) is to compare just the file names---file names differ if
1520 they do not appear in the other directory. You can specify
1521 more stringent comparisons by entering a Lisp expression, which can
1522 refer to the variables @code{size1} and @code{size2}, the respective
1523 file sizes; @code{mtime1} and @code{mtime2}, the last modification
1524 times in seconds, as floating point numbers; and @code{fa1} and
1525 @code{fa2}, the respective file attribute lists (as returned by the
1526 function @code{file-attributes}). This expression is evaluated for
1527 each pair of like-named files, and files differ if the expression's
1528 value is non-@code{nil}.
1530 For instance, the sequence @kbd{M-x dired-compare-directories
1531 @key{RET} (> mtime1 mtime2) @key{RET}} marks files newer in this
1532 directory than in the other, and marks files older in the other
1533 directory than in this one. It also marks files with no counterpart,
1534 in both directories, as always.
1536 @cindex drag and drop, Dired
1537 On the X Window System, Emacs supports the drag and drop
1538 protocol. You can drag a file object from another program, and drop
1539 it onto a Dired buffer; this either moves, copies, or creates a link
1540 to the file in that directory. Precisely which action is taken is
1541 determined by the originating program. Dragging files out of a Dired
1542 buffer is currently not supported.