My current best bet is:
for i in $(find . -name *.jpg); do echo $i; done
Problem: does not handle spaces in filenames.
Note: I would also love a graphical way of doing this, such as the "tree" command.
The canonical way is to do
or (GNU specific, though some BSDs now have it as well):
Better answers have already been given.
But note that spaces are not the only problem in the code you gave. tab, newline and wildcard characters are also a problem.
Then only newline characters are a problem.
What you have mentioned is one of the basic problems that people face, when they try to read file names. Sometimes, people with limited knowledge and having a misconception of file and folder structure tend to forget that "In UNIX Everything is a file" . So they don't understand that they need to handle spaces as well, as the file name can consist of 2 or more words with spaces.
Solution : So one of the better known ways of doing this is to do a clean read .
We here will read all the files present and keep them in a variable, next time when doing the desired processing we just will have to keep that variable inside quotes which will preserve the file names with spaces. This is one of the basic ways of doing it, however, the other answers provided by the other people here work just as well.
Here i am reading the files by giving the path to them and whatever i am reading i am keeping them inside a variable I, which i will quote at a later point while processing it to preserve the spaces so as to process it correctly.
Hope this helps you in some way.
This way, we use
A more efficient way (to avoid having to start a new bash for every file):
In recent version of bash, you can use the
For simple actions, you can even skip the loop entirely: