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