2

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.

2
  • The docstring does say how to do that. Maybe it could be more clear/explicit on that. Commented 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. Commented Oct 30, 2019 at 17:28

1 Answer 1

4

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:

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

Documentation
...
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 ?.

1
  • 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. Commented Oct 30, 2019 at 15:26

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.