If I run this command:
sudo find . -name *.mp3
then I can get a listing of lots of mp3 files.
Now I want to do something with each mp3 file in a loop. For example, I could create a while
loop, and inside assign the first file name to the variable file
. Then I could do something with that file. Next I could assign the second file name to the variable file
and do with that, etc.
How can I realize this using a linux shell command? Any help is appreciated, thanks!
For this, use the read
builtin:
sudo find . -name *.mp3 |
while read filename
do
echo "$filename" # ... or any other command using $filename
done
Provided that your filenames don't use the newline (\n
) character, this should work fine.
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