Comments on How to run a command on a list of files?
Parent
How to run a command on a list of files?
+4
−0
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?
Post
+4
−0
Works for me
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