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