Iterating over each line of ls -l output

前端 未结 6 2031
长发绾君心
长发绾君心 2020-12-12 11:32

I want to iterate over each line in the output of: ls -l /some/dir/*

Right now I\'m trying: for x in $(ls -l $1); do echo $x; done

6条回答
  •  借酒劲吻你
    2020-12-12 12:25

    So, why didn't anybody suggest just using options that eliminate the parts he doesn't want to process.

    On modern Debian you just get your file with:

    ls --format=single-column 
    

    Further more, you don't have to pay attention to what directory you are running it in if you use the full directory:

    ls --format=single-column /root/dir/starting/point/to/target/dir/
    

    This last command I am using the above and I get the following output:

    bot@dev:~/downloaded/Daily# ls --format=single-column /home/bot/downloaded/Daily/*.gz
    /home/bot/downloaded/Daily/Liq_DailyManifest_V3_US_20141119_IENT1.txt.gz
    /home/bot/downloaded/Daily/Liq_DailyManifest_V3_US_20141120_IENT1.txt.gz
    /home/bot/downloaded/Daily/Liq_DailyManifest_V3_US_20141121_IENT1.txt.gz
    

提交回复
热议问题