Iterating over each line of ls -l output

前端 未结 6 2027
长发绾君心
长发绾君心 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:04

    You can also try the find command. If you only want files in the current directory:

    find . -d 1 -prune -ls

    Run a command on each of them?

    find . -d 1 -prune -exec echo {} \;

    Count lines, but only in files?

    find . -d 1 -prune -type f -exec wc -l {} \;

提交回复
热议问题