Comments on How to run a command on a list of files?
Parent
How to run a command on a list of files?
Suppose I have a list of files on standard input. These may be the output of find
, cat filelist.txt
or something else.
How can I run a command on each file in turn?
There are several options, like `xargs` and `for`. I'll leave those for other answers and only describe my favorite, GNU …
11mo ago
If I just used `find` to generate a list of files, then find's `-exec` argument is usually the way to run some other pr …
11mo ago
In some cases, when you want to apply a pipeline or a complex command to each file, I find it useful to use `while read` …
7mo ago
To run a command on a list of files, use a combination of commands and file glob patterns. For example, on Unix-based sy …
1mo ago
To run a command on a list of files, you can use a command-line interface and a loop statement. For example, in Linux, y …
1mo ago
Post
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
LAFK | (no comment) | Jun 21, 2023 at 05:59 |
-
If I just used
find
to generate a list of files, then find's-exec
argument is usually the way to run some other program on each file found.If you pipe the command to
xargs
, note that-P n
will run up to n commands in parallel. The best value of n will depend on the relative usage of your CPU and your storage system. -
If I have a program (say,
generate_lists
) that generates a list of files,for filename in $(generate_lists); do some_program "$filename" ; done
is usually helpful. Make sure you quote your use of
$filename
-- more of them have spaces than you'd think.
0 comment threads