I want to execute a formatted shell command on a file from within Dired. I am aware that I can use dired-do-shell-command to run a shell command on a selected file file by entering

! <command>

to run

<command> file

Ideally I want to run

! <command> file <additional-arguments>

In other words I want to be able to specify where in the command file appears. I tried running

! <command> {} <additional-arguments> 

and reading the doc for dired-do-shell-command, but neither of those gave me the solution to achieve this.

  • The docstring does say how to do that. Maybe it could be more clear/explicit on that.
    – JeanPierre
    Oct 30, 2019 at 17:16
  • Now that jue pointed it out I realize it. What put me off was that that the infostring used the term file list whereas I had my mind fixed on an individual file. Therefore i disregarded that part of the infostring as unrelated to my issue. My bad.
    – fossegrim
    Oct 30, 2019 at 17:28

1 Answer 1


Simply add your parameters to the command prompt, separated by space, without any placeholder for filenames.
To construct commands like ls -l <file>, just enter ls -l.

OR: the interface supports the placeholders * and ?.
Where ? means call command with one marked file only, in a loop;
and * means call with all marked files.
Read more at masteringemacs.org

Example: (ls would be your <command> and -l would be your <additional-arguments>).
You could enter ls * -l as command for example to run ls <files> -l once (with all marked files at once).
Or you could enter ls ? -l to run ls <file> -l for every single file.

Edit: dired-do-shell-command help string:

(dired-do-shell-command COMMAND &optional ARG FILE-LIST)

If there is a * in COMMAND, surrounded by whitespace, this runs COMMAND just once with the entire file list substituted there.

If there is no *, but there is a ? in COMMAND, surrounded by whitespace, this runs COMMAND on each file individually with the file name substituted for ?.

  • Thank you! That was exactly what I was looking for. I gave you an upvote, but it does not show up because I am a new user.
    – fossegrim
    Oct 30, 2019 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.