ls command in Linux with options

Good Evening Guys! So, Today we will learn the most popular and mostly used command in Linux which is ls command. It is mostly used to list the files and folders.

With the help of ls command, we can check the permission, file type, username group, and many more. We will discuss this in detail in the same post.

So, Let’s start with our first command with the Practice link

$ ls
output:
exam  file  linux  practice  taste  the

As you can see the above the files and folder are listed, but how can we say whether the exam is the folder or a file.

-l option is for a long listing

$ ls -l
output:
drwxrwxr-x 2 tla tla 4096 Apr 19 19:28 exam
-rw-rw-r-- 1 tla tla    0 Apr 19 19:29 file
drwxrwxr-x 2 tla tla 4096 Apr 19 19:28 linux
drwxrwxr-x 2 tla tla 4096 Apr 19 19:28 practice
drwxrwxr-x 2 tla tla 4096 Apr 19 19:28 taste
drwxrwxr-x 2 tla tla 4096 Apr 19 19:28 the

Now you can see the highlighted part in red color that is d and , this are the file types, -d is denoted as directory and – is the regular file.

a option will see all the file including hidden file.

$ ls -a 
output:
.  ..  hacked  linux  paper  quiz

So the .(dot) in the blue colour is the hidden directory in the Linux.

-R option will list the subdirectories in recursively format.

To Check the Sub-directory in the exam ls -R command output

So, as you can see exam that is a folder in that current directory, So in the exam folder there was hacked, linux and paper and also contain a file named as quiz.

But now the -R option was also searched in the hacked, linux and paper directory.

-r option to reverse order while sorting use with option -l

$ ls -lr 
output:
-rw-rw-r-- 1 tla tla    0 Apr 19 19:56 quiz
drwxrwxr-x 2 tla tla 4096 Apr 19 19:56 paper
drwxrwxr-x 2 tla tla 4096 Apr 19 19:56 linux
drwxrwxr-x 2 tla tla 4096 Apr 19 19:56 hacked

So, the above example has sorted by the alphabetical order from Z to A. Now we will sort this by time, Let’s see that with -t option

t option to sort the file by modification time
$ ls -lrt 
output:
drwxrwxr-x 2 tla tla 4096 Apr 19 18:56 paper
drwxrwxr-x 2 tla tla 4096 Apr 19 19:46 linux
drwxrwxr-x 2 tla tla 4096 Apr 19 20:59 hacked
-rw-rw-r-- 1 tla tla    0 Apr 19 21:50 quiz
drwxrwxr-x 2 tla tla 4096 Apr 19 22:56 comp
-rw-rw-r-- 1 tla tla    0 Apr 19 23:01 learn_new

Just look at the red highlighted part in the above example, you can see the timings, the last file learn_new is the latest one, but that file is at the last file because we have used -r option to reverse the things.

So, Guys, we can say that to see the latest file you can use the command “ls -lrt

s option to print the size of the files

$ ls -s
output:
total 130732
     4 exam  130724 p4v.tgz       4 test

So, the above output shows the data in bytes, let’s use -h option so, that we can read the output easily.

h option for the human-readable

$ ls -hs 
output:
total 128M
4.0K exam  128M p4v.tgz  4.0K test

The human readable means the size of the file in kb, mb and gb.

As, we can clearly see the size of the file in the above output.

S option to sort by file size

$ ls -lS 
output:
total 130732
-rw-r--r-- 1 root root 133855793 Apr 21 22:06 p4v.tgz
drwxrwxr-x 6 tla  tla       4096 Apr 19 23:01 exam
drwxrwxr-x 3 tla  tla       4096 Apr 20 15:05 test

Above example can justify that -S option sorted by file size

$ man ls

This is known as the MANUAL page of ls command, where you can get more options for this command.

So, Lets Play the QUIZ for the ls command

Icon_for_the_Quiz
0%

Correct the syntax for ls command friends

Please select 2 correct answers

Correct! Wrong!

How we can list the all files and folders

Please select 2 correct answers

Correct! Wrong!

How to sort the file size in reverse order try, if you can

The bigger file size should be the last file of the list
Show hint
Correct! Wrong!

See the old file in the list, Answer please friends

Please select 2 correct answers

The old file will be the last file of the list
Show hint
Correct! Wrong!

So, look at man page of ls and Answer please, How we can see the inodes of files and folders?

Please select 2 correct answers

Look at the man page of ls
Show hint
Correct! Wrong!

How we can see the hidden files from ls command

looking for hint, it is also hidden.
Show hint
Correct! Wrong!

ls -A command is for? try on the terminal guys!

Correct! Wrong!

What will -g option will be used for?

Please select 2 correct answers

Check the man quickly for the answer.
Show hint
Correct! Wrong!

Why we use -B option with ls command?

Check the man Page for the Answer
Show hint
Correct! Wrong!

The -B option is used for ignoring Backups, But the Backup file end with ~ this sign.

How to list all the files and folder that start with "letter t" ?

Please select 2 correct answers

Use Wildcard
Show hint
Correct! Wrong!

Let's Learn and Play with ls command
Thanks for the Participation in the Quiz!!
To Learn more Linux Basic command, Please visit to Basic Command Section.

Share your Results:

ls command cheat sheet
1. list the directory and files

Syntax:
ls [directory_name] and [File_name]

Example: 
#ls tastethelinux  
#ls 
2.long listing the directory and files

Syntax:
ls [option] [directory_name] and [File_name]

Example: 
#ls -l tastethelinux  
#ls -l
3. To check the hidden directory and files

Syntax:
ls [option]

Example: 
#ls -a
4. To check the sub directory

Syntax:
ls [option] [directory_name]

Example: 
#ls -R tastethelinux
5. To check the output in reverse order

Syntax:
ls [option]

Example: 
#ls -r 
6. To check the files and folder as per the modification

Syntax:
ls [option] [directory_name] and [File_name]

Example: 
#ls [option] tastethelinux
#ls -t
7. To check the size of the file and folder

Syntax:
ls [option] [directory_name] and [File_name]

Example: 
#ls -s tastethelinux
8. To Sort by size 

Syntax:
ls [option]

Example: 
#ls -S tastethelinux
9. For human readable use with -l option

Syntax:
ls [option]

Example: 
#ls -lh
10. To check the inode of the files and folder

Syntax:
ls [option]

Example: 
#ls -i tastethelinux
#ls -i
11. To ignore the backup files

Syntax:
ls [option]

Example: 
#ls -B
12. To check the hidden file without . and ..

Syntax:
ls [option]

Example: 
#ls -A
13. To check the group of files and folders

Syntax:
ls [option]

Example: 
#ls -g
14. To seprate the output with commas 

Syntax:
ls [option]

Example: 
#ls -m

Check how to create directory in Linux with there different options.

Thank you Guys to read this post! Support us Guys

ls cheat sheet, ls command in Linux

2 Replies to “ls command in Linux with options

Give your valuable time