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