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