Running a script on all files in a directory tree
I am attempting to run a c++ program on all the images in a directory and all of its sub directories. To do this I run
find . -type f -exec file '{}' \; The c++ program outputs the results to standard out, and I want to redirect to a file for each image, so if the program is running on a.jpeg I want a file called a.txt (or a.jpeg.txt would be fine). I try find . -type f -exec file '{}' > '{}'.txt \; But this only creates a file named {}.txt. How do I get it to recognize the {} as the name of the current file after the >? Is there a way to do this in one command on the command line (or a different post I failed to find that explains how)? |
By not wrapping it in single quotes? Just kidding - that's only
half the problem. The other half is that you can't use the {} twice ... Use a wrapper: Code:
for i in $(find -type f) |
Solved
Works, thank you!
|
The problem is solved. However I will make a slight comment for the sake of correctness.
Quote:
Code:
for i in $HOME -mexdepth 1 -exec echo '{}' '{}' \; The problem with his expression is that the redirection operator takes precedence (and anyway, even if it didn't, find doesn't have a meaning for it anyway. So, the find command ends where the redirection starts, and the second '{}' is not in the land of find, but in the land of bash, outside find. For bash, '{}' has no special meaning, and is a textual string (and so, it's printed as that, without any kind of expansion attached to it. So, piping the names into a loop is probably the best way: Code:
find whatever | while read file |
All times are GMT -5. The time now is 11:55 PM. |