1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Rep Power

    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.
  2. #2
  3. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Rep Power
    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

IMN logo majestic logo threadwatch logo seochat tools logo