I have a text file files.txt
on my server, on each line is a file with the full path, e.g. /home/lelouch/dir/randomfile.txt
.
I want to loop through files.txt, and pass each filename to another script.
I have gotten this to work like this:
cat /home/lelouch/dir/files.txt | xargs -0 -n 1 -P 30 /home/lelouch/bin/script.
The problem is, although I want to process it 30 files at a time, it's only happening 1 at a time. I've tried a few other ways, but I haven't gotten it to work like I want.
Any ideas?
You say that each line is a filepath, but you use the -0
option of xargs
, which switches the separator from a newline to a null character. From the man
page:
Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally)....
Don't use the -0
option:
cat /home/lelouch/dir/files.txt | xargs -P 30 -n 1 /home/lelouch/bin/script
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With