Get top or bottom 10 files under a director from terminal (on Ubuntu and Mac)

This post get top/bottom 10 from the sorted file names in current directory.

For reading the first line of a file from terminal (on Ubuntu and Mac), check here.

Note: you do not need to install anything, it is built-in on your Ubuntu/Mac OS.

Step 1: open a terminal 

Step 2: cd to the directory where your file (e.g., .txt file) is located 

Step 3: issue the following command accordingly

$ ls | head -10

# the pipe symbol (i.e., |) puts the output of the ls command as the input of the head command.

if you would like to get more information of the files, use the following instead:

$ ls -l | head -10


if you would like to get the bottom 10 files in the current directory, issue the following command:

$ ls | tail -10

or for detailed information of the files, use

$ ls -l | tail -10

You guessed it, if you would like to get the top/bottom 20, just change the -10 to -20:)

simply, enough, right?


For more commonly used Linux commands, check my other posts at here  and here .

Leave a Reply

Your email address will not be published. Required fields are marked *