Iterating over each line of ls -l output

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

    It depends what you want to do with each line. awk is a useful utility for this type of processing. Example:

     ls -l | awk '{print $9, $5}'
    

    .. on my system prints the name and size of each item in the directory.

提交回复
热议问题