In bash, how can I print the first n elements of a list?

后端 未结 8 1238
死守一世寂寞
死守一世寂寞 2021-02-19 20:00

In bash, how can I print the first n elements of a list?

For example, the first 10 files in this list:

FILES=$(ls)
8条回答
  •  忘了有多久
    2021-02-19 20:46

    My way would be:

    ls | head -10 | tr "\n" " "
    

    This will print the first 10 lines returned by ls, and then tr replaces all line breaks with spaces. Output will be on a single line.

提交回复
热议问题