Bash Command for Each File in a Folder
I Have a Set of Files on Which I Would Like to Apply the Same Command and the Output Should Contain the Same Name as the Processed File but with a Different...
I have a set of files on which I would like to apply the same command and the output should contain the same name as the processed file but with a different extension.
Currently I am doing rename /my/data/Andrew.doc to /my/data/Andrew.txt I would like to do this for all the .doc files from the /my/data/ folder and to preserve the name.
I tried several versions but I guess I have something wrong in the syntax as I an new to linux.
2 Answers
There are at least a hundred thousand million different ways of approaching this but here are the top contenders:
Must Read
The Bash for loop
for f in ./*.doc; do
# do some stuff here with "$f"
# remember to quote it or spaces may misbehave
done