(dired.info)Dired Shell Commands
Next: Compressing and Uncompressing Prev: Deleting Files With Dired Up: Mark-using Commands
Shell Commands on Marked files
You can run arbitrary shell commands on the marked files. If there is
output, it goes to a separate buffer.
(`dired-do-shell-command') Run a shell command on the marked files.
A command string is prompted for in the minibuffer. The list of
marked files is appended to the command string unless asterisks `*'
indicate the place(s) where the list should go. Thus,
is equivalent to
command -flags *
The filenames are inserted in the order they appear in the buffer.
The file listed topmost in the buffer will be the leftmost in the list.
Currently, there is no way to insert a real `*' into the command.
As with all mark-using commands, if no files are marked or a specific
numeric prefix arg is given, the current or the next N files are used.
The prompt mentions the file(s) or the marker, as appropriate.
However, for shell commands, a zero argument is special. It means to
run command on each marked file separately:
cmd * |foo
cmd F1 |foo; ...; cmd FN |foo
cmd F1 ... FN |foo
would be executed.
No automatic redisplay is attempted because Dired cannot know what
files should be redisplayed for a general shell command. For example, a
`tar cvf' will not change the marked files at all, but rather create a
new file, while a `ci -u -m'...' *' will probably change the permission
bits of all marked files.
Type `l' to redisplay just the marked files, or `l' on a directory
headerline to redisplay just that directory, or `g' to redisplay all
The shell command has the top level directory as working directory,
so output files usually are created there instead of in a subdirectory,
which may sometimes be surprising if all files come from the same
subdirectory. Just remember that an Emacs buffer can have but one
working directory, and this is the top level directory in Dired buffers.
Examples for shell commands:
* Type `!' and
tar cvf foo.tar
to tar all marked files into a `foo.tar' file. Dired does not know
that a new file has been created and you have to type `g' to
refresh the listing. If you have several subdirectories in your
Dired buffer, the names given to `tar' will be relative to the top
level directory, and the output file `foo.tar' will also be created
You can use
tar cvf - * | compress -c > foo.tar.Z
as an alternative to immediately compress the tar file.
* Type `0 !' and
to uudecode each of the marked files. Note the use of the zero
prefix argument to apply the shell command to each file separately
(uudecode doesn't accept a list of input files). Type `g'
afterwards to see the created files.
* Type `0 !' and
uuencode * * >*.uu
to uuencode each of the marked files, writing into a corresponding
`.uu' file. Note the use of the zero prefix argument to apply the
shell command to each file separately. Type `g' afterwards to see
the created `.uu' files.
* Type `1 !' and
mail joe@somewhere <*
to mail the current file (note the prefix argument `1') to user
* Here is a Dired shell command to execute the current file,
assuming no other files are marked (else just give the prefix `1'
which will be expanded to `./CMD', thus CMD will be executed..
(Just `./' would be expanded to `./ CMD', with an intervening
`SPC'.) This will work even if you don't have `.' in your
`$PATH'. If `.' is in your path (not a good idea, as you will
find out if you dired a directory containing a file named `ls'), a
single `SPC' as command would also work.
automatically generated by info2www