(diff-kill-junk): New interactive function.
[emacs.git] / man / dired.texi
blob17144977a37bcd6fef25a10a9dfd659dc00170b7
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985, 86, 87, 93-95, 97, 2000 Free Software Foundation, Inc.
3 @c See file emacs.texi for copying conditions.
4 @node Dired, Calendar/Diary, Rmail, Top
5 @chapter Dired, the Directory Editor
6 @cindex Dired
8   Dired makes an Emacs buffer containing a listing of a directory, and
9 optionally some of its subdirectories as well.  You can use the normal
10 Emacs commands to move around in this buffer, and special Dired commands
11 to operate on the files listed.
13 @menu
14 * Enter: Dired Enter.         How to invoke Dired.
15 * Commands: Dired Commands.   Commands in the Dired buffer.
16 * Deletion: Dired Deletion.   Deleting files with Dired.
17 * Flagging Many Files::       Flagging files based on their names.
18 * Visit: Dired Visiting.      Other file operations through Dired.
19 * Marks vs Flags::            Flagging for deletion vs marking.
20 * Operating on Files::        How to copy, rename, print, compress, etc.
21                                 either one file or several files.
22 * Shell Commands in Dired::   Running a shell command on the marked files.
23 * Transforming File Names::   Using patterns to rename multiple files.
24 * Comparison in Dired::       Running `diff' by way of Dired.
25 * Subdirectories in Dired::   Adding subdirectories to the Dired buffer.
26 * Subdirectory Motion::       Moving across subdirectories, and up and down.
27 * Hiding Subdirectories::     Making subdirectories visible or invisible.
28 * Updating: Dired Updating.   Discarding lines for files of no interest.
29 * Find: Dired and Find.       Using `find' to choose the files for Dired.
30 * Extra Features for Dired::  Dired-X provides more features.
31 @end menu
33 @node Dired Enter
34 @section Entering Dired
36 @findex dired
37 @kindex C-x d
38 @vindex dired-listing-switches
39   To invoke Dired, do @kbd{C-x d} or @kbd{M-x dired}.  The command reads
40 a directory name or wildcard file name pattern as a minibuffer argument
41 to specify which files to list.  Where @code{dired} differs from
42 @code{list-directory} is in putting the buffer into Dired mode so that
43 the special commands of Dired are available.
45   The variable @code{dired-listing-switches} specifies the options to
46 give to @code{ls} for listing directory; this string @emph{must} contain
47 @samp{-l}.  If you use a numeric prefix argument with the @code{dired}
48 command, you can specify the @code{ls} switches with the minibuffer
49 before you enter the directory specification.
51 @findex dired-other-window
52 @kindex C-x 4 d
53 @findex dired-other-frame
54 @kindex C-x 5 d
55   To display the Dired buffer in another window rather than in the
56 selected window, use @kbd{C-x 4 d} (@code{dired-other-window}) instead
57 of @kbd{C-x d}.  @kbd{C-x 5 d} (@code{dired-other-frame}) uses a
58 separate frame to display the Dired buffer.
60 @node Dired Commands
61 @section Commands in the Dired Buffer
63     The Dired buffer is ``read-only,'' and inserting text in it is not
64 useful, so ordinary printing characters such as @kbd{d} and @kbd{x} are
65 used for special Dired commands.  Some Dired commands @dfn{mark} or
66 @dfn{flag} the @dfn{current file} (that is, the file on the current
67 line); other commands operate on the marked files or on the flagged
68 files.
70 @kindex C-n @r{(Dired)}
71 @kindex C-p @r{(Dired)}
72   All the usual Emacs cursor motion commands are available in Dired
73 buffers.  Some special-purpose cursor motion commands are also
74 provided.  The keys @kbd{C-n} and @kbd{C-p} are redefined to put the
75 cursor at the beginning of the file name on the line, rather than at the
76 beginning of the line.
78 @kindex SPC @r{(Dired)}
79   For extra convenience, @key{SPC} and @kbd{n} in Dired are equivalent
80 to @kbd{C-n}.  @kbd{p} is equivalent to @kbd{C-p}.  (Moving by lines is
81 so common in Dired that it deserves to be easy to type.)  @key{DEL}
82 (move up and unflag) is often useful simply for moving up.
84 @node Dired Deletion
85 @section Deleting Files with Dired
86 @cindex flagging files (in Dired)
87 @cindex deleting files (in Dired)
89   The primary use of Dired is to @dfn{flag} files for deletion and then
90 delete the files previously flagged.
92 @table @kbd
93 @item d
94 Flag this file for deletion.
95 @item u
96 Remove deletion flag on this line.
97 @item @key{DEL}
98 Move point to previous line and remove the deletion flag on that line.
99 @item x
100 Delete the files that are flagged for deletion.
101 @end table
103 @kindex d @r{(Dired)}
104 @findex dired-flag-file-deletion
105   You can flag a file for deletion by moving to the line describing the
106 file and typing @kbd{d} (@code{dired-flag-file-deletion}).  The deletion flag is visible as a @samp{D} at
107 the beginning of the line.  This command moves point to the next line,
108 so that repeated @kbd{d} commands flag successive files.  A numeric
109 argument serves as a repeat count.
110 @vindex dired-recursive-deletes
111 The variable @code{dired-recursive-deletes} determines if the delete
112 command will delete non-empty directories recursively.  The default
113 is to delete only empty directories.
115 @kindex u @r{(Dired deletion)}
116 @kindex DEL @r{(Dired)}
117   The files are flagged for deletion rather than deleted immediately to
118 reduce the danger of deleting a file accidentally.  Until you direct
119 Dired to expunge the flagged files, you can remove deletion flags using
120 the commands @kbd{u} and @key{DEL}.  @kbd{u} (@code{dired-unmark}) works
121 just like @kbd{d}, but removes flags rather than making flags.
122 @key{DEL} (@code{dired-unmark-backward}) moves upward, removing flags;
123 it is like @kbd{u} with argument @minus{}1.
125 @kindex x @r{(Dired)}
126 @findex dired-expunge
127 @cindex expunging (Dired)
128   To delete the flagged files, type @kbd{x} (@code{dired-expunge}).
129 This command first displays a list of all the file names flagged for
130 deletion, and requests confirmation with @kbd{yes}.  If you confirm,
131 Dired deletes the flagged files, then deletes their lines from the text
132 of the Dired buffer.  The shortened Dired buffer remains selected.
134   If you answer @kbd{no} or quit with @kbd{C-g} when asked to confirm, you
135 return immediately to Dired, with the deletion flags still present in
136 the buffer, and no files actually deleted.
138 @node Flagging Many Files
139 @section Flagging Many Files at Once
141 @table @kbd
142 @item #
143 Flag all auto-save files (files whose names start and end with @samp{#})
144 for deletion (@pxref{Auto Save}).
146 @item ~
147 Flag all backup files (files whose names end with @samp{~}) for deletion
148 (@pxref{Backup}).
150 @item &
151 Flag for deletion all files with certain kinds of names, names that
152 suggest you could easily create the files again.
154 @item .@: @r{(Period)}
155 Flag excess numeric backup files for deletion.  The oldest and newest
156 few backup files of any one file are exempt; the middle ones are
157 flagged.
159 @item % d @var{regexp} @key{RET}
160 Flag for deletion all files whose names match the regular expression
161 @var{regexp}.
162 @end table
164   The @kbd{#}, @kbd{~}, @kbd{&}, and @kbd{.} commands flag many files for
165 deletion, based on their file names.  These commands are useful
166 precisely because they do not themselves delete any files; you can
167 remove the deletion flags from any flagged files that you really wish to
168 keep.@refill
170 @kindex & @r{(Dired)}
171 @findex dired-flag-garbage-files
172 @vindex dired-garbage-files-regexp
173   @kbd{&} (@code{dired-flag-garbage-files}) flags files whose names
174 match the regular expression specified by the variable
175 @code{dired-garbage-files-regexp}.  By default, this matches certain
176 files produced by @TeX{}, and the @samp{.orig} and @samp{.rej} files
177 produced by @code{patch}.
179 @kindex # @r{(Dired)}
180 @kindex ~ @r{(Dired)}
181 @findex dired-flag-auto-save-files
182 @findex dired-flag-backup-files
183   @kbd{#} (@code{dired-flag-auto-save-files}) flags for deletion all
184 files whose names look like auto-save files (@pxref{Auto Save})---that
185 is, files whose names begin and end with @samp{#}.  @kbd{~}
186 (@code{dired-flag-backup-files}) flags for deletion all files whose
187 names say they are backup files (@pxref{Backup})---that is, whose names
188 end in @samp{~}.
190 @kindex . @r{(Dired)}
191 @vindex dired-kept-versions
192 @findex dired-clean-directory
193   @kbd{.} (period, @code{dired-clean-directory}) flags just some of the
194 backup files for deletion: all but the oldest few and newest few backups
195 of any one file.  Normally @code{dired-kept-versions} (@strong{not}
196 @code{kept-new-versions}; that applies only when saving) specifies the
197 number of newest versions of each file to keep, and
198 @code{kept-old-versions} specifies the number of oldest versions to
199 keep.
201   Period with a positive numeric argument, as in @kbd{C-u 3 .},
202 specifies the number of newest versions to keep, overriding
203 @code{dired-kept-versions}.  A negative numeric argument overrides
204 @code{kept-old-versions}, using minus the value of the argument to
205 specify the number of oldest versions of each file to keep.
207 @findex dired-flag-files-regexp
208 @kindex % d @r{(Dired)}
209   The @kbd{% d} command flags all files whose names match a specified
210 regular expression (@code{dired-flag-files-regexp}).  Only the
211 non-directory part of the file name is used in matching.  You can use
212 @samp{^} and @samp{$} to anchor matches.  You can exclude subdirectories
213 by hiding them (@pxref{Hiding Subdirectories}).
215 @node Dired Visiting
216 @section Visiting Files in Dired
218   There are several Dired commands for visiting or examining the files
219 listed in the Dired buffer.  All of them apply to the current line's
220 file; if that file is really a directory, these commands invoke Dired on
221 that subdirectory (making a separate Dired buffer).
223 @table @kbd
224 @item f
225 @kindex f @r{(Dired)}
226 @findex dired-find-file
227 Visit the file described on the current line, like typing @kbd{C-x C-f}
228 and supplying that file name (@code{dired-find-file}).  @xref{Visiting}.
230 @item @key{RET}
231 @kindex RET @r{(Dired)}
232 Equivalent to @kbd{f}.
234 @item o
235 @kindex o @r{(Dired)}
236 @findex dired-find-file-other-window
237 Like @kbd{f}, but uses another window to display the file's buffer
238 (@code{dired-find-file-other-window}).  The Dired buffer remains visible
239 in the first window.  This is like using @kbd{C-x 4 C-f} to visit the
240 file.  @xref{Windows}.
242 @item C-o
243 @kindex C-o @r{(Dired)}
244 @findex dired-display-file
245 Visit the file described on the current line, and display the buffer in
246 another window, but do not select that window (@code{dired-display-file}).
248 @item Mouse-2
249 @findex dired-mouse-find-file-other-window
250 Visit the file named by the line you click on
251 (@code{dired-mouse-find-file-other-window}).  This uses another window
252 to display the file, like the @kbd{o} command.
254 @item v
255 @kindex v @r{(Dired)}
256 @findex dired-view-file
257 View the file described on the current line, using @kbd{M-x view-file}
258 (@code{dired-view-file}).
260 Viewing a file is like visiting it, but is slanted toward moving around
261 in the file conveniently and does not allow changing the file.
262 @xref{Misc File Ops,View File}.
263 @end table
265 @node Marks vs Flags
266 @section Dired Marks vs. Flags
268 @cindex marking in Dired
269   Instead of flagging a file with @samp{D}, you can @dfn{mark} the file
270 with some other character (usually @samp{*}).  Most Dired commands to
271 operate on files, aside from ``expunge'' (@kbd{x}), look for files
272 marked with @samp{*}.
274   Here are some commands for marking with @samp{*}, or for unmarking or
275 operating on marks.  (@xref{Dired Deletion}, for commands to flag and
276 unflag files.)
278 @table @kbd
279 @item m
280 @itemx * m
281 @kindex m @r{(Dired)}
282 @kindex * m @r{(Dired)}
283 @findex dired-mark
284 Mark the current file with @samp{*} (@code{dired-mark}).  With a numeric
285 argument @var{n}, mark the next @var{n} files starting with the current
286 file.  (If @var{n} is negative, mark the previous @minus{}@var{n}
287 files.)
289 @item * *
290 @kindex * * @r{(Dired)}
291 @findex dired-mark-executables
292 Mark all executable files with @samp{*}
293 (@code{dired-mark-executables}).  With a numeric argument, unmark all
294 those files.
296 @item * @@
297 @kindex * @@ @r{(Dired)}
298 @findex dired-mark-symlinks
299 Mark all symbolic links with @samp{*} (@code{dired-mark-symlinks}).
300 With a numeric argument, unmark all those files.
302 @item * /
303 @kindex * / @r{(Dired)}
304 @findex dired-mark-directories
305 Mark with @samp{*} all files which are actually directories, except for
306 @file{.} and @file{..} (@code{dired-mark-directories}).  With a numeric
307 argument, unmark all those files.
309 @item * s
310 @kindex * s @r{(Dired)}
311 @findex dired-mark-subdir-files
312 Mark all the files in the current subdirectory, aside from @file{.}
313 and @file{..} (@code{dired-mark-subdir-files}).
315 @item u
316 @itemx * u
317 @kindex u @r{(Dired)}
318 @kindex * u @r{(Dired)}
319 @findex dired-unmark
320 Remove any mark on this line (@code{dired-unmark}).
322 @item @key{DEL}
323 @itemx * @key{DEL}
324 @kindex * DEL @r{(Dired)}
325 @findex dired-unmark-backward
326 Move point to previous line and remove any mark on that line
327 (@code{dired-unmark-backward}).
329 @item * !
330 @kindex * ! @r{(Dired)}
331 @findex dired-unmark-all-files-no-query
332 Remove all marks from all the files in this Dired buffer
333 (@code{dired-unmark-all-files-no-query}).
335 @item * ? @var{markchar}
336 @kindex * ? @r{(Dired)}
337 @findex dired-unmark-all-files
338 Remove all marks that use the character @var{markchar}
339 (@code{dired-unmark-all-files}).  The argument is a single
340 character---do not use @key{RET} to terminate it.
342 With a numeric argument, this command queries about each marked file,
343 asking whether to remove its mark.  You can answer @kbd{y} meaning yes,
344 @kbd{n} meaning no, or @kbd{!} to remove the marks from the remaining
345 files without asking about them.
347 @item * C-n
348 @findex dired-next-marked-file
349 @kindex * C-n @r{(Dired)}
350 Move down to the next marked file (@code{dired-next-marked-file})
351 A file is ``marked'' if it has any kind of mark.
353 @item * C-p
354 @findex dired-prev-marked-file
355 @kindex * C-p @r{(Dired)}
356 Move up to the previous marked file (@code{dired-prev-marked-file})
358 @item * t
359 @kindex * t @r{(Dired)}
360 @findex dired-do-toggle
361 Toggle all marks (@code{dired-do-toggle}): files marked with @samp{*}
362 become unmarked, and unmarked files are marked with @samp{*}.  Files
363 marked in any other way are not affected.
365 @item * c @var{old} @var{new}
366 @kindex * c @r{(Dired)}
367 @findex dired-change-marks
368 Replace all marks that use the character @var{old} with marks that use
369 the character @var{new} (@code{dired-change-marks}).  This command is
370 the primary way to create or use marks other than @samp{*} or @samp{D}.
371 The arguments are single characters---do not use @key{RET} to terminate
372 them.
374 You can use almost any character as a mark character by means of this
375 command, to distinguish various classes of files.  If @var{old} is a
376 space (@samp{ }), then the command operates on all unmarked files; if
377 @var{new} is a space, then the command unmarks the files it acts on.
379 To illustrate the power of this command, here is how to put @samp{D}
380 flags on all the files that have no marks, while unflagging all those
381 that already have @samp{D} flags:
383 @example
384 * c D t  * c SPC D  * c t SPC
385 @end example
387 This assumes that no files are marked with @samp{t}.
389 @item % m @var{regexp} @key{RET}
390 @itemx * % @var{regexp} @key{RET}
391 @findex dired-mark-files-regexp
392 @kindex % m @r{(Dired)}
393 @kindex * % @r{(Dired)}
394 Mark (with @samp{*}) all files whose names match the regular expression
395 @var{regexp} (@code{dired-mark-files-regexp}).  This command is like
396 @kbd{% d}, except that it marks files with @samp{*} instead of flagging
397 with @samp{D}.  @xref{Flagging Many Files}.
399 Only the non-directory part of the file name is used in matching.  Use
400 @samp{^} and @samp{$} to anchor matches.  Exclude subdirectories by
401 hiding them (@pxref{Hiding Subdirectories}).
403 @item % g @var{regexp} @key{RET}
404 @findex dired-mark-files-containing-regexp
405 @kindex % m @r{(Dired)}
406 Mark (with @samp{*}) all files whose @emph{contents} contain a match for
407 the regular expression @var{regexp}
408 (@code{dired-mark-files-containing-regexp}).  This command is like
409 @kbd{% m}, except that it searches the file contents instead of the file
410 name.
412 @item C-_
413 @kindex C-_ @r{(Dired)}
414 @findex dired-undo
415 Undo changes in the Dired buffer, such as adding or removing
416 marks (@code{dired-undo}).
417 @end table
419 @node Operating on Files
420 @section Operating on Files
421 @cindex operating on files in Dired
423   This section describes the basic Dired commands to operate on one file
424 or several files.  All of these commands are capital letters; all of
425 them use the minibuffer, either to read an argument or to ask for
426 confirmation, before they act.  All of them give you several ways to
427 specify which files to manipulate:
429 @itemize @bullet
430 @item
431 If you give the command a numeric prefix argument @var{n}, it operates
432 on the next @var{n} files, starting with the current file.  (If @var{n}
433 is negative, the command operates on the @minus{}@var{n} files preceding
434 the current line.)
436 @item
437 Otherwise, if some files are marked with @samp{*}, the command operates
438 on all those files.
440 @item
441 Otherwise, the command operates on the current file only.
442 @end itemize
444   Here are the file-manipulating commands that operate on files in this
445 way.  (Some other Dired commands, such as @kbd{!} and the @samp{%}
446 commands, also use these conventions to decide which files to work on.)
448 @table @kbd
449 @findex dired-do-copy
450 @kindex C @r{(Dired)}
451 @item C @var{new} @key{RET}
452 Copy the specified files (@code{dired-do-copy}).  The argument @var{new}
453 is the directory to copy into, or (if copying a single file) the new
454 name.
455 @vindex dired-recursive-copies
456 The variable @code{dired-recursive-copies} determines if directories are
457 copied recursively.  The default is to not copy recursively.
459 @vindex dired-copy-preserve-time
460 If @code{dired-copy-preserve-time} is non-@code{nil}, then copying with
461 this command sets the modification time of the new file to be the same
462 as that of the old file.
464 @item D
465 @findex dired-do-delete
466 @kindex D @r{(Dired)}
467 Delete the specified files (@code{dired-do-delete}).  Like the other
468 commands in this section, this command operates on the @emph{marked}
469 files, or the next @var{n} files.  By contrast, @kbd{x}
470 (@code{dired-expunge}) deletes all @dfn{flagged} files.
472 @findex dired-do-rename
473 @kindex R @r{(Dired)}
474 @item R @var{new} @key{RET}
475 Rename the specified files (@code{dired-do-rename}).  The argument
476 @var{new} is the directory to rename into, or (if renaming a single
477 file) the new name.
479 Dired automatically changes the visited file name of buffers associated
480 with renamed files so that they refer to the new names.
482 @findex dired-do-hardlink
483 @kindex H @r{(Dired)}
484 @item H @var{new} @key{RET}
485 Make hard links to the specified files (@code{dired-do-hardlink}).  The
486 argument @var{new} is the directory to make the links in, or (if making
487 just one link) the name to give the link.
489 @findex dired-do-symlink
490 @kindex S @r{(Dired)}
491 @item S @var{new} @key{RET}
492 Make symbolic links to the specified files (@code{dired-do-symlink}).
493 The argument @var{new} is the directory to make the links in, or (if
494 making just one link) the name to give the link.
496 @findex dired-do-chmod
497 @kindex M @r{(Dired)}
498 @item M @var{modespec} @key{RET}
499 Change the mode (also called ``permission bits'') of the specified files
500 (@code{dired-do-chmod}).  This uses the @code{chmod} program, so
501 @var{modespec} can be any argument that @code{chmod} can handle.
503 @findex dired-do-chgrp
504 @kindex G @r{(Dired)}
505 @item G @var{newgroup} @key{RET}
506 Change the group of the specified files to @var{newgroup}
507 (@code{dired-do-chgrp}).
509 @findex dired-do-chown
510 @kindex O @r{(Dired)}
511 @item O @var{newowner} @key{RET}
512 Change the owner of the specified files to @var{newowner}
513 (@code{dired-do-chown}).  (On most systems, only the superuser can do
514 this.)
516 @vindex dired-chown-program
517 The variable @code{dired-chown-program} specifies the name of the
518 program to use to do the work (different systems put @code{chown} in
519 different places).
521 @findex dired-do-print
522 @kindex P @r{(Dired)}
523 @item P @var{command} @key{RET}
524 Print the specified files (@code{dired-do-print}).  You must specify the
525 command to print them with, but the minibuffer starts out with a
526 suitable guess made using the variables @code{lpr-command} and
527 @code{lpr-switches} (the same variables that @code{lpr-buffer} uses;
528 @pxref{Hardcopy}).
530 @findex dired-do-compress
531 @kindex Z @r{(Dired)}
532 @item Z
533 Compress the specified files (@code{dired-do-compress}).  If the file
534 appears to be a compressed file already, it is uncompressed instead.
536 @findex dired-do-load
537 @kindex L @r{(Dired)}
538 @item L
539 Load the specified Emacs Lisp files (@code{dired-do-load}).
540 @xref{Lisp Libraries}.
542 @findex dired-do-byte-compile
543 @kindex B @r{(Dired)}
544 @item B
545 Byte compile the specified Emacs Lisp files
546 (@code{dired-do-byte-compile}).  @xref{Byte Compilation,, Byte
547 Compilation, elisp, The Emacs Lisp Reference Manual}.
549 @kindex A @r{(Dired)}
550 @findex dired-do-search
551 @item A @var{regexp} @key{RET}
552 Search all the specified files for the regular expression @var{regexp}
553 (@code{dired-do-search}).
555 This command is a variant of @code{tags-search}.  The search stops at
556 the first match it finds; use @kbd{M-,} to resume the search and find
557 the next match.  @xref{Tags Search}.
559 @kindex Q @r{(Dired)}
560 @findex dired-do-query-replace
561 @item Q @var{from} @key{RET} @var{to} @key{RET}
562 Perform @code{query-replace-regexp} on each of the specified files,
563 replacing matches for @var{from} (a regular expression) with the string
564 @var{to} (@code{dired-do-query-replace}).
566 This command is a variant of @code{tags-query-replace}.  If you exit the
567 query replace loop, you can use @kbd{M-,} to resume the scan and replace
568 more matches.  @xref{Tags Search}.
570 @kindex a @r{(Dired)}
571 @findex dired-do-apply
572 @item a @var{function} @kbd{RET}
573 Apply an arbitrary Lisp function to the name of each marked file
574 (@code{dired-do-apply}).
575 @end table
577 @kindex + @r{(Dired)}
578 @findex dired-create-directory
579   One special file-operation command is @kbd{+}
580 (@code{dired-create-directory}).  This command reads a directory name and
581 creates the directory if it does not already exist.
583 @node Shell Commands in Dired
584 @section Shell Commands in Dired
585 @cindex shell commands, Dired
587 @findex dired-do-shell-command
588 @kindex ! @r{(Dired)}
589 The dired command @kbd{!} (@code{dired-do-shell-command}) reads a shell
590 command string in the minibuffer and runs that shell command on all the
591 specified files.  You can specify the files to operate on in the usual
592 ways for Dired commands (@pxref{Operating on Files}).  There are two
593 ways of applying a shell command to multiple files:
595 @itemize @bullet
596 @item
597 If you use @samp{*} in the shell command, then it runs just once, with
598 the list of file names substituted for the @samp{*}.  The order of file
599 names is the order of appearance in the Dired buffer.
601 Thus, @kbd{! tar cf foo.tar * @key{RET}} runs @code{tar} on the entire
602 list of file names, putting them into one tar file @file{foo.tar}.
604 @item
605 If the command string doesn't contain @samp{*}, then it runs once
606 @emph{for each file}, with the file name added at the end.
608 For example, @kbd{! uudecode @key{RET}} runs @code{uudecode} on each
609 file.
610 @end itemize
612 What if you want to run the shell command once for each file but with
613 the file name inserted in the middle?  Or if you want to use the file
614 names in a more complicated fashion?  Use a shell loop.  For example,
615 this shell command would run @code{uuencode} on each of the specified
616 files, writing the output into a corresponding @file{.uu} file:
618 @example
619 for file in *; do uuencode $file $file >$file.uu; done
620 @end example
622 @noindent
623 In simple cases you can instead use @samp{?} in the command.  This is
624 similar to @samp{*} but the command will be run on each file
625 individually.
627 The working directory for the shell command is the top-level directory
628 of the Dired buffer.
630 The @kbd{!} command does not attempt to update the Dired buffer to show
631 new or modified files, because it doesn't really understand shell
632 commands, and does not know what files the shell command changed.  Use
633 the @kbd{g} command to update the Dired buffer (@pxref{Dired
634 Updating}).
636 @node Transforming File Names
637 @section Transforming File Names in Dired
639   Here are commands that alter file names in a systematic way:
641 @table @kbd
642 @findex dired-upcase
643 @kindex % u @r{(Dired)}
644 @item % u
645 Rename each of the selected files to an upper-case name
646 (@code{dired-upcase}).  If the old file names are @file{Foo}
647 and @file{bar}, the new names are @file{FOO} and @file{BAR}.
649 @item % l
650 @findex dired-downcase
651 @kindex % l @r{(Dired)}
652 Rename each of the selected files to a lower-case name
653 (@code{dired-downcase}).  If the old file names are @file{Foo} and
654 @file{bar}, the new names are @file{foo} and @file{bar}.
656 @item % R @var{from} @key{RET} @var{to} @key{RET}
657 @kindex % R @r{(Dired)}
658 @findex dired-do-rename-regexp
659 @itemx % C @var{from} @key{RET} @var{to} @key{RET}
660 @kindex % C @r{(Dired)}
661 @findex dired-do-copy-regexp
662 @itemx % H @var{from} @key{RET} @var{to} @key{RET}
663 @kindex % H @r{(Dired)}
664 @findex dired-do-hardlink-regexp
665 @itemx % S @var{from} @key{RET} @var{to} @key{RET}
666 @kindex % S @r{(Dired)}
667 @findex dired-do-symlink-regexp
668 These four commands rename, copy, make hard links and make soft links,
669 in each case computing the new name by regular-expression substitution
670 from the name of the old file.
671 @end table
673   The four regular-expression substitution commands effectively perform
674 a search-and-replace on the selected file names in the Dired buffer.
675 They read two arguments: a regular expression @var{from}, and a
676 substitution pattern @var{to}.
678   The commands match each ``old'' file name against the regular
679 expression @var{from}, and then replace the matching part with @var{to}.
680 You can use @samp{\&} and @samp{\@var{digit}} in @var{to} to refer to
681 all or part of what the pattern matched in the old file name, as in
682 @code{replace-regexp} (@pxref{Regexp Replace}).  If the regular expression
683 matches more than once in a file name, only the first match is replaced.
685   For example, @kbd{% R ^.*$ @key{RET} x-\& @key{RET}} renames each
686 selected file by prepending @samp{x-} to its name.  The inverse of this,
687 removing @samp{x-} from the front of each file name, is also possible:
688 one method is @kbd{% R ^x-\(.*\)$ @key{RET} \1 @key{RET}}; another is
689 @kbd{% R ^x- @key{RET} @key{RET}}.  (Use @samp{^} and @samp{$} to anchor
690 matches that should span the whole filename.)
692   Normally, the replacement process does not consider the files'
693 directory names; it operates on the file name within the directory.  If
694 you specify a numeric argument of zero, then replacement affects the
695 entire absolute file name including directory name.
697   Often you will want to select the set of files to operate on using the
698 same @var{regexp} that you will use to operate on them.  To do this,
699 mark those files with @kbd{% m @var{regexp} @key{RET}}, then use the
700 same regular expression in the command to operate on the files.  To make
701 this easier, the @kbd{%} commands to operate on files use the last
702 regular expression specified in any @kbd{%} command as a default.
704 @node Comparison in Dired
705 @section File Comparison with Dired
707   Here are two Dired commands that compare specified files using
708 @code{diff}.
710 @table @kbd
711 @item =
712 @findex dired-diff
713 @kindex = @r{(Dired)}
714 Compare the current file (the file at point) with another file (the file
715 at the mark) using the @code{diff} program (@code{dired-diff}).  The
716 file at the mark is the first argument of @code{diff}, and the file at
717 point is the second argument.
719 @findex dired-backup-diff
720 @kindex M-= @r{(Dired)}
721 @item M-=
722 Compare the current file with its latest backup file
723 (@code{dired-backup-diff}).  If the current file is itself a backup,
724 compare it with the file it is a backup of; this way, you can compare
725 a file with any backup version of your choice.
727 The backup file is the first file given to @code{diff}.
728 @end table
730 @node Subdirectories in Dired
731 @section Subdirectories in Dired
732 @cindex subdirectories in Dired
733 @cindex expanding subdirectories in Dired
735   A Dired buffer displays just one directory in the normal case;
736 but you can optionally include its subdirectories as well.
738   The simplest way to include multiple directories in one Dired buffer is
739 to specify the options @samp{-lR} for running @code{ls}.  (If you give a
740 numeric argument when you run Dired, then you can specify these options
741 in the minibuffer.)  That produces a recursive directory listing showing
742 all subdirectories at all levels.
744   But usually all the subdirectories are too many; usually you will
745 prefer to include specific subdirectories only.  You can do this with
746 the @kbd{i} command:
748 @table @kbd
749 @findex dired-maybe-insert-subdir
750 @kindex i @r{(Dired)}
751 @item i
752 @cindex inserted subdirectory (Dired)
753 @cindex in-situ subdirectory (Dired)
754 Insert the contents of a subdirectory later in the buffer.
755 @end table
757 Use the @kbd{i} (@code{dired-maybe-insert-subdir}) command on a line
758 that describes a file which is a directory.  It inserts the contents of
759 that directory into the same Dired buffer, and moves there.  Inserted
760 subdirectory contents follow the top-level directory of the Dired
761 buffer, just as they do in @samp{ls -lR} output.
763 If the subdirectory's contents are already present in the buffer, the
764 @kbd{i} command just moves to it.
766 In either case, @kbd{i} sets the Emacs mark before moving, so @kbd{C-u
767 C-@key{SPC}} takes you back to the old position in the buffer (the line
768 describing that subdirectory).
770 Use the @kbd{l} command (@code{dired-do-redisplay}) to update the
771 subdirectory's contents.  Use @kbd{k} to delete the subdirectory.
772 @xref{Dired Updating}.
774 @node Subdirectory Motion
775 @section Moving Over Subdirectories
777   When a Dired buffer lists subdirectories, you can use the page motion
778 commands @kbd{C-x [} and @kbd{C-x ]} to move by entire directories.
780 @cindex header line (Dired)
781 @cindex directory header lines
782   The following commands move across, up and down in the tree of
783 directories within one Dired buffer.  They move to @dfn{directory header
784 lines}, which are the lines that give a directory's name, at the
785 beginning of the directory's contents.
787 @table @kbd
788 @findex dired-next-subdir
789 @kindex C-M-n @r{(Dired)}
790 @item C-M-n
791 Go to next subdirectory header line, regardless of level
792 (@code{dired-next-subdir}).
794 @findex dired-prev-subdir
795 @kindex C-M-p @r{(Dired)}
796 @item C-M-p
797 Go to previous subdirectory header line, regardless of level
798 (@code{dired-prev-subdir}).
800 @findex dired-tree-up
801 @kindex C-M-u @r{(Dired)}
802 @item C-M-u
803 Go up to the parent directory's header line (@code{dired-tree-up}).
805 @findex dired-tree-down
806 @kindex C-M-d @r{(Dired)}
807 @item C-M-d
808 Go down in the directory tree, to the first subdirectory's header line
809 (@code{dired-tree-down}).
811 @findex dired-prev-dirline
812 @kindex < @r{(Dired)}
813 @item <
814 Move up to the previous directory-file line (@code{dired-prev-dirline}).
815 These lines are the ones that describe a directory as a file in its
816 parent directory.
818 @findex dired-next-dirline
819 @kindex > @r{(Dired)}
820 @item >
821 Move down to the next directory-file line (@code{dired-prev-dirline}).
822 @end table
824 @node Hiding Subdirectories
825 @section Hiding Subdirectories
827 @cindex hiding in Dired (Dired)
828   @dfn{Hiding} a subdirectory means to make it invisible, except for its
829 header line, via selective display (@pxref{Selective Display}).
831 @table @kbd
832 @item $
833 @findex dired-hide-subdir
834 @kindex $ @r{(Dired)}
835 Hide or reveal the subdirectory that point is in, and move point to the
836 next subdirectory (@code{dired-hide-subdir}).  A numeric argument serves
837 as a repeat count.
839 @item M-$
840 @findex dired-hide-all
841 @kindex M-$ @r{(Dired)}
842 Hide all subdirectories in this Dired buffer, leaving only their header
843 lines (@code{dired-hide-all}).  Or, if any subdirectory is currently
844 hidden, make all subdirectories visible again.  You can use this command
845 to get an overview in very deep directory trees or to move quickly to
846 subdirectories far away.
847 @end table
849   Ordinary Dired commands never consider files inside a hidden
850 subdirectory.  For example, the commands to operate on marked files
851 ignore files in hidden directories even if they are marked.  Thus you
852 can use hiding to temporarily exclude subdirectories from operations
853 without having to remove the markers.
855   The subdirectory hiding commands toggle; that is, they hide what was
856 visible, and show what was hidden.
858 @node Dired Updating
859 @section Updating the Dired Buffer
861   This section describes commands to update the Dired buffer to reflect
862 outside (non-Dired) changes in the directories and files, and to delete
863 part of the Dired buffer.
865 @table @kbd
866 @item g
867 Update the entire contents of the Dired buffer (@code{revert-buffer}).
869 @item l
870 Update the specified files (@code{dired-do-redisplay}).
872 @item k
873 Delete the specified @emph{file lines}---not the files, just the lines
874 (@code{dired-do-kill-lines}).
876 @item s
877 Toggle between alphabetical order and date/time order
878 (@code{dired-sort-toggle-or-edit}).
880 @item C-u s @var{switches} @key{RET}
881 Refresh the Dired buffer using @var{switches} as
882 @code{dired-listing-switches}.
883 @end table
885 @kindex g @r{(Dired)}
886 @findex revert-buffer @r{(Dired)}
887   Type @kbd{g} (@code{revert-buffer}) to update the contents of the
888 Dired buffer, based on changes in the files and directories listed.
889 This preserves all marks except for those on files that have vanished.
890 Hidden subdirectories are updated but remain hidden.
892 @kindex l @r{(Dired)}
893 @findex dired-do-redisplay
894   To update only some of the files, type @kbd{l}
895 (@code{dired-do-redisplay}).  This command applies to the next @var{n}
896 files, or to the marked files if any, or to the current file.  Updating
897 them means reading their current status from the file system and
898 changing the buffer to reflect it properly.
900   If you use @kbd{l} on a subdirectory header line, it updates the
901 contents of the corresponding subdirectory.
903 @kindex k @r{(Dired)}
904 @findex dired-do-kill-lines
905   To delete the specified @emph{file lines}---not the files, just the
906 lines---type @kbd{k} (@code{dired-do-kill-lines}).  With a numeric
907 argument @var{n}, this command applies to the next @var{n} files;
908 otherwise, it applies to the marked files.
910   If you kill the line for a file that is a directory, the directory's
911 contents are also deleted from the buffer.  Typing @kbd{C-u k} on the
912 header line for a subdirectory is another way to delete a subdirectory
913 from the Dired buffer.
915   The @kbd{g} command brings back any individual lines that you have
916 killed in this way, but not subdirectories---you must use @kbd{i} to
917 reinsert each subdirectory.
919 @cindex Dired sorting
920 @cindex sorting Dired buffer
921 @kindex s @r{(Dired)}
922 @findex dired-sort-toggle-or-edit
923   The files in a Dired buffers are normally listed in alphabetical order
924 by file names.  Alternatively Dired can sort them by date/time.  The
925 Dired command @kbd{s} (@code{dired-sort-toggle-or-edit}) switches
926 between these two sorting modes.  The mode line in a Dired buffer
927 indicates which way it is currently sorted---by name, or by date.
929   @kbd{C-u s @var{switches} @key{RET}} lets you specify a new value for
930 @code{dired-listing-switches}.
932 @node Dired and Find
933 @section Dired and @code{find}
934 @cindex @code{find} and Dired
936   You can select a set of files for display in a Dired buffer more
937 flexibly by using the @code{find} utility to choose the files.
939 @findex find-name-dired
940   To search for files with names matching a wildcard pattern use
941 @kbd{M-x find-name-dired}.  It reads arguments @var{directory} and
942 @var{pattern}, and chooses all the files in @var{directory} or its
943 subdirectories whose individual names match @var{pattern}.
945   The files thus chosen are displayed in a Dired buffer in which the
946 ordinary Dired commands are available.
948 @findex find-grep-dired
949   If you want to test the contents of files, rather than their names,
950 use @kbd{M-x find-grep-dired}.  This command reads two minibuffer
951 arguments, @var{directory} and @var{regexp}; it chooses all the files in
952 @var{directory} or its subdirectories that contain a match for
953 @var{regexp}.  It works by running the programs @code{find} and
954 @code{grep}.  See also @kbd{M-x grep-find}, in @ref{Compilation}.
955 Remember to write the regular expression for @code{grep}, not for Emacs.
957 @findex find-dired
958   The most general command in this series is @kbd{M-x find-dired}, which
959 lets you specify any condition that @code{find} can test.  It takes two
960 minibuffer arguments, @var{directory} and @var{find-args}; it runs
961 @code{find} in @var{directory}, passing @var{find-args} to tell
962 @code{find} what condition to test.  To use this command, you need to
963 know how to use @code{find}.
965 @vindex find-ls-option
966   The format of listing produced by these commands is controlled by the
967 variable @code{find-ls-option}, whose default value specifies using
968 options @samp{-ld} for @code{ls}.  If your listings are corrupted, you
969 may need to change the value of this variable.
971 @node Extra Features for Dired
972 @section Extra Features for Dired---The Dired-X Package
974 The Dired-X package provides various extra features for Dired mode.  You
975 can load it with @code{M-x load-library} or customize
976 @code{dired-load-hook} to add @samp{(require@w{ }'dired-x)}.
977 @xref{Top, Introduction, dired-x, Dired Extra Version 2 User's Manual}.