How do I limit the number of displayed lines through ls?
Andrew Henderson
Let's say I have a command
ls -Bgclt /somwhere/in/the/pastHow do I limit the output to show me only first 2 files? (except for having only 2 files in that directory)
2 Answers
Simple - you pipe the output through head:
ls -Bgclt /somwhere/in/the/past | head -n 3You use -n 3 instead of -n 2 because of the 'total' line at the top of the ls output.
0If you are really picky and only want to see the name of those two lines (that is, you want to exclude that first line with the word 'total' at the top) you can try
ls -Bgclt /somwhere/in/the/past | head -n 3 | tail -n 2 2