Linux Commands with "ls"
Tags: linux, beginners, discuss, devops
Published: 2021-04-10 13:04:46

Welcome back..

In previous article, I have posted about Linux File hierarchy structure [Link](https://dev.to/satizzzzz/all-you-need-to-know-about-linux-file-hierarchy-structure-5807) , please check if you haven't visited.
 
**ls** is one of basic commands which lists files/directories that one should know when working with Linux. It is used on daily basis even though we may not aware and never use of all the ls options that are available.

In this article, we will be seeing purpose and different ways of using **ls** commands with options in Linux.


####1.List files using ls with no option

ls with no options lists all the files and directories in a bare format with no other details like file size, owner, permissions, date and time.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i64pukeee2g5qphrkjzg.png)



####2.List files using ls with option -l

ls -l will lists the available files and directories with details like file/directory name size, owner, permissions, date and time.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40y1n45sver46v0r87jj.png)


 
####3.View hidden files

ls -a will lists hidden files available

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ac8n2lep37uzpb38nhs3.png)



####4.List Files in Human Readable Format with option -lh

You know ls -l will list files/directories along with size and other details. By adding h(Human Readable Format) to it, ls -lh will lists files/directory size in human readable format like bytes, Kb, Gb

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4wakloytwqgb7mh6gkfk.png)


 
####5.List Directories adding / at the end with option -F

ls -F will list files and add "/" at the end of directories

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j2iqsppel8f3a3146htp.png)
 

 
####6.List Files/Directories in reverse order

ls -r will list files/directories in reverse order

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ji27efcptyc7y7h9of8c.png)



####7.Recursively lists Sub-directories

ls -R list all files that are available inside the sub-directories

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lv0q9oqq4v4rryznmk26.png)



####8.Listing latest updated files/directories 

ls -ltr will lists files and directories in reverse order with latest modification as last

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8nq8h60kzpgf68dch44e.png)



####9.Sorting files by file size

ls -lS will lists the file size in order, by displaying big size first

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6m2q1lfq6iej8fjlj93.png)



####10.Display Inode number of File or Directory 

Inode number is unique identification number that are assigned when new file/directory is created.

ls -i will display the inode number of a file/directory

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fsol5oidrv41n5gbo9hd.png)
 


####11.ls version

ls --version will return the version of ls

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wznvcm42ap5p3vcu02dz.png)



####12.Show help page

ls --help will display the help page

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xd8r86p4ba0fzls33ymx.png)



####13.List directory information

ls -l /Dir_name will lists all the files/directories inside the defined directory

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kt9d71dh4ml3csr7kfqr.png)



####14.Display UID and GID of Files

ls -n will display the UserID and GroupID of files/directories

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fhejnfksrdcj0kl14kqy.png)


Hope the above information is useful. :)