Operating on Files
This section describes the basic Dired commands to operate on one file or several files. All of these commands are capital letters; all of them use the minibuffer, either to read an argument or to ask for confirmation, before they act. All of them let you specify the files to manipulate in these ways:
- If you give the command a numeric prefix argument n, it operates on the next n files, starting with the current file. (If n is negative, the command operates on the -n files preceding the current line.)
- Otherwise, if some files are marked with
*, the command operates on all those files. - Otherwise, the command operates on the current file only.
@noindent Certain other Dired commands, such as ! and the % commands, use the same conventions to decide which files to work on. In addition to Dired commands described here, you can also invoke Version Control (VC) commands on one or more files shown in a Dired buffer. Version Control. Commands which ask for a destination directory, such as those which copy and rename files or create links for them, try to guess the default target directory for the operation. Normally, they suggest the Dired buffer's default directory, but if the option dired-dwim-target is non-nil, and if there is another Dired buffer displayed in some window, that other buffer's directory is suggested instead. You can customize dired-dwim-target to prefer either the next window with a Dired buffer, or the most recently used window with a Dired buffer, or to use any other function. When the value is a function, it will be called with no arguments and is expected to return a list of directories which will be used as defaults (i.e., default target and ``future history''). Here are the file-manipulating Dired commands that operate on files.
-
C new
RET - Copy the specified files (
dired-do-copy). The argument new is the directory to copy into, or (if copying a single file) the new name. This is like the shell commandcp. The optiondired-create-destination-dirscontrols whether Dired should create non-existent directories in the destination while copying/renaming files. The default valuenilmeans Dired never creates such missing directories; the valuealways, means Dired automatically creates them; the valueaskmeans Dired asks you for confirmation before creating them. If the optiondired-create-destination-dirs-on-trailing-dirsepis non-nilin addition todired-create-destination-dirs, a trailing directory separator at the destination directory is treated specially. In that case, when copying totest/and no directorytestexists already, it will be created and the specified source files or directories are copied into the newly created directory. Ifdired-copy-preserve-timeis non-nil, then copying with this command preserves the modification time of the old file in the copy, likecp -p. The variabledired-recursive-copiescontrols whether to copy directories recursively (likecp -r). The default istop, which means to ask before recursively copying a directory. The variabledired-copy-dereferencecontrols whether to copy symbolic links as links or after dereferencing (likecp -L). The default isnil, which means that the symbolic links are copied by creating new ones. Thedired-keep-marker-copyuser option controls how this command handles file marking. The default is to mark all new copies of files with aCmark. - D
- Delete the specified files (
dired-do-delete). This is like the shell commandrm. Like the other commands in this section, this command operates on the marked files, or the next n files. By contrast,x(dired-do-flagged-delete) deletes all flagged files. - E
- ``Open'' the specified files using an external program (
dired-do-open). The program is selected according to the system conventions, as determined by the variableshell-command-guess-open. -
R new
RET - Rename the specified files (
dired-do-rename). If you rename a single file, the argument new is the new name of the file. If you rename several files, the argument new is the directory into which to move the files (this is like the shell commandmv). The optiondired-create-destination-dirscontrols whether Dired should create non-existent directories in new. The optiondired-create-destination-dirs-on-trailing-dirsep, when set in addition todired-create-destination-dirs, controls whether a trailing directory separator at the destination is treated specially. In that case, when renaming a directoryoldtonew/and no directorynewexists already, it will be created andoldis moved into the newly created directory. Otherwise,oldis renamed tonew. Dired automatically changes the visited file name of buffers associated with renamed files so that they refer to the new names. If the value of the variabledired-vc-rename-fileis non-nil, files are renamed using the commands of the underlying VCS, viavc-rename-file(VC Delete/Rename). -
H new
RET - Make hard links to the specified files (
dired-do-hardlink). This is like the shell commandln. The argument new is the directory to make the links in, or (if making just one link) the name to give the link. -
S new
RET - Make symbolic links to the specified files (
dired-do-symlink). This is likeln -s. The argument new is the directory to make the links in, or (if making just one link) the name to give the link. -
Y new
RET - Make relative symbolic links to the specified files (
dired-do-relsymlink). The argument new is the directory to make the links in, or (if making just one link) the name to give the link. This is likedired-do-symlinkbut creates relative symbolic links. For example: @example foo -> ../bar/foo @end example It does not create absolute ones like: @example foo -> /path/that/may/change/any/day/bar/foo @end example -
M modespec
RET - Change the mode (also called permission bits) of the specified files (
dired-do-chmod). modespec can be in octal or symbolic notation, like arguments handled by thechmodprogram. This command does not follow symbolic links, so it reports an error if you try to change the mode of a symbolic link on a platform where such modes are immutable. -
G newgroup
RET - Change the group of the specified files to newgroup (
dired-do-chgrp). -
O newowner
RET - Change the owner of the specified files to newowner (
dired-do-chown). (On most systems, only the superuser can do this.) The variabledired-chown-programspecifies the name of the program to use to do the work. (This variable is necessary because different systems putchownin different places). -
T timestamp
RET - Touch the specified files (
dired-do-touch). This means updating their modification times to timestamp, which defaults to the present time. This is like the shell commandtouch. -
P command
RET - Print the specified files (
dired-do-print). You must specify the command to print them with, but the minibuffer starts out with a suitable guess made using the variableslpr-commandandlpr-switches(the same variables thatlpr-bufferuses; Printing). - Z
- Compress the specified files (
dired-do-compress). If the file appears to be a compressed file already, uncompress it instead. Each marked file is compressed into its own archive; this uses thegzipprogram if it is available, otherwise it usescompress. On a directory name, this command produces a compressed archive depending on thedired-compress-directory-default-suffixuser option. The default is a.tar.gzarchive containing all of the directory's files, by running thetarcommand with output piped togzip. To allow decompression of compressed directories, typingZon a.tar.gzor.tgzarchive file unpacks all the files in the archive into a directory whose name is the archive name with the extension removed. - c
- Compress the specified files (
dired-do-compress-to) into a single archive anywhere on the file system. The default archive is controlled by thedired-compress-directory-default-suffixuser option. Also seedired-compress-files-alist. - :d
- Decrypt the specified files (
epa-dired-do-decrypt). Dired integration. - :v
- Verify digital signatures on the specified files (
epa-dired-do-verify). Dired integration. - :s
- Digitally sign the specified files (
epa-dired-do-sign). Dired integration. - :e
- Encrypt the specified files (
epa-dired-do-encrypt). Dired integration. - L
- Load the specified Emacs Lisp files (
dired-do-load). Lisp Libraries. - B
- Byte compile the specified Emacs Lisp files (
dired-do-byte-compile). Byte Compilation. - I
- Run Info on this file (assumed to be a file in Info format).
- N
- Run man on this file (assumed to be a file in
nroffformat). -
A regexp
RET - Search all the specified files for the regular expression regexp (
dired-do-find-regexp). This command is a variant ofxref-find-references(Identifier Search), it displays the*xref*buffer, where you can navigate between matches and display them as needed using the commands described in Xref Commands. If any of the marked files are directories, then this command searches all of the files in those directories, and any of their subdirectories, recursively, except files whose names matchgrep-find-ignored-filesand subdirectories whose names matchgrep-find-ignored-directories. -
Q regexp
RETtoRET - Perform
query-replace-regexpon each of the specified files, replacing matches for regexp with the string to (dired-do-find-regexp-and-replace). This command is a variant ofxref-query-replace-in-results. It presents an*xref*buffer that lists all the matches of regexp, and you can use the special commands in that buffer (Xref Commands). In particular, if you exit the query replace loop, you can userin that buffer to replace more matches. Identifier Search. Like withdired-do-find-regexp, if any of the marked files are directories, this command performs replacements in all of the files in those directories, and in any of their subdirectories, recursively, except for files whose names matchgrep-find-ignored-filesand subdirectories whose names matchgrep-find-ignored-directories.