March 11th, 2011, 01:03 AM
List files using Loop
I was hoping someone could tell me how to list the files in a directory one by one using a loop. I know it's possible to just put ls -l directory1, but I want to go through the files in the directory one by one and list them that way.
My script file is called forloop
for file in $(ls -a $1)
ls -l $1/$file
When I run: forloop junk1 I get a listing of ALL my files when I just want a listing of files in junk1.
March 11th, 2011, 04:21 PM
the -l (ell) option for ls is the long listing, so when the object of that is a directory, it will list the directory ... In the loop you could either use -ld or filter out directories in the loop control if you want to.
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc