ls command

About ls command

full form = list 

With the help of ls command, list the contents present inside the directory. 

Command:

ls [OPTION] [FILE_PATH]

Note: Default value of FILE_PATH is current working directory.

Some useful options with examples are given below -

1. ls  :  Lists files and directories present inside a directory with no options.


2. ls -a (or ls --all):  Some files are hidden inside the directory, they are called hidden files. In such a situation, with the help of  -a(--all) option, you can list all types of files whether hidden or not.

OR
 

When we ran ls command then .f.txt , .k.txt files and .game directory were not display but with the help of -a( --all)  option all files are display.

3. ls -l :  With the help of this command, the files present inside the directory can be displayed in long format.  
Several columns are visible here, the first character of the first column indicates the type of file.

The file types are shown below:-

d : directory 
-  : ordinary file
l  : link file
s  : socket file 




Column 1

The first character in the first column is -, which means this file is an ordinary file.
Thus

drwx------ = file android is                 directory.                        
-rwx------  = file b.txt is ordinary file
-rwx------  = file c.txt is ordinary file
drwx------ = file dir is directory
lrwxrwxrwx = file sl.txt is link file

The last 9 characters of the first column represent the file permissions.

Column 2


The numbers in column 2 represent the total number of links to the file.

File a.txt has 1 and directory android  has 2 links.

Column 3



This column shows the owner name of the file .
# u0_a222 is owner of  file a.txt 

Column 4 


 Column 4 represent  group owner of file .

Column 5 : represent size of the file .

Column 6 : last modification month of file .

Column 7: last modification day of file in given month.

Column 8: last modification time 

Column 9: represent name of the file .

3. ls -t (or ls --time): this command sort according to newest file. This means new file will be displayed first and oldest file will be displayed last.

4. ls -s (or ls --size):  Find out the size of the file with the help of this command.


5. ls -S : With the help of this command, we can arrange the file according to the largest file size.
It means largest first and smallest last.

directory android is largest file and c.txt  is smallest

6. ls -r (or ls --reverse): With the help of -r (or --reverse) , the contents of the directory can be reversed in order.

You can see the difference in the output of  ls  command and ls -r command.

7. ls -R (or ls --recursive):
Recursively list subdirectories inside a directory.

8. ls -i (or ls --inode):  Option -i is used to find the inode number of a file or directory.

9. ls -n :  Through this, get the group ID and user ID of files and directories.

The third and fourth columns represent the User ID and Group ID respectively.


I have tried to make it easy to understand by taking the Linux manual page as a reference.

If you liked this article, please help others by sharing.If there is anything incorrect in this or it needs more improvement then you can comment me in the comment box below or contact at  query.me

 .  


Comments

Popular posts from this blog

wc Command

ifconfig command