ls command is one of the most frequently used command in Linux. With no option, this command list files and directories in bare format where you won’t be able to view details like file types, size, modified date and time, permission and links. There are many options you can use with ls command.
1. List Files With option -l
Here, ls -l shows file or directory, size, modified date and time, file or folder name and owner of file and its permission.
The first character specifies the type of the file. The hyphen (-) indicates that this is a normal file.
- - : normal file
- d : directory
- s : socket file
- l : link file
Next nine character specifies the file permission. The every 3 characters specifies read (r), write (w), execute (x) permissions for user, group and others respectively in order.
Second field specifies the number of links for that file. Third field specifies owner of the file. Fourth field specifies the group of the file. Fifth field specifies the size of file in bytes. Sixth field specifies the date and time of the last modification of the file. The last field is the name of the file.
2. View Hidden Files
List all files including hidden file starting with ‘.‘.
3. Human Readable Format
List Files with Human Readable Format with option -lh
To display file size in easy to read format - M for MB, K for KB, G for GB.
4. List with ‘/’ Character at the end
Using -F option with ls command, will add the ‘/’ Character at the end each directory.
5. Reverse Order
List files and directories in reverse order.
6. Recursively list Subdirectories
This option will list very long listing directory trees.
7. Sort by Time and Date
It sorts the files by modification time, showing the last edited file first.
8. Reverse Output Order
With combination of -ltr, this command will show latest modification file or directory date as last.
9. Sort Files by File Size
With combination of -lS displays file size in order, will display big in size first.