I have this command to go to every directory and once there run some command over every file:
STDIR=$PWD;
for dir in $(find . -type d 2>&-); do
cd "$dir";
for file in $(find * -prune -type f 2>&-); do
command "$file";
done;
cd "$STDIR";
done
But there is a problem when the files or directories have spaces in the name. How can I fix that?
This doubt appear when trying to apply an answer to this question.
Edit:
A good solution also appear in this comment. To solve the spaces problem, add
IFS=$'\n'
after the first line of the code above, and
unset IFS
after done.
There are three ways:
The third solution has an advantage: you need not so many forks as in the variants (1) and (2). And when you need to process quite many lines it can become important.