15 Basic ‘ls’ Command Examples in Linux

15 Basic ‘ls’ Command

ls command is one of the most frequently used command in Linux. I believe ls command is the first command you may use when you get into the command prompt of Linux Box.

We use ls command daily basis and frequently even though we may not aware and never use all the ls option available. In this article, we’ll be discussing basic ls command where we have tried to cover as much parameters as possible.

1. List Files using ls with no option

ls with no option list files and directories in bare format where we won’t be able to view details like file types, size, modified date and time, permission and links etc.

2 List Files With option –l

Here, ls -l (-l is character not one) shows file or directory, size, modified date and time, file or folder name and owner of file and it’s permission.

3. View Hidden Files

List all files including hidden file starting with ‘.‘.

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

With combination of -lh option, shows sizes in human readable format.

5. List Files and Directories with ‘/’ Character at the end

Using -F option with ls command, will add the ‘/’ Character at the end each directory.

6. List Files in Reverse Order

The following command with ls -r option display files and directories in reverse order.

7. Recursively list Sub-Directories

ls -R option will list very long listing directory trees. See an example of output of the command.

8. Reverse Output Order

With combination of -ltr will shows 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.

10. Display Inode number of File or Directory

We can see some number printed before file / directory name. With -i options list file / directory with inode number.

11. Shows version of ls command

Check version of ls command.

12. Show Help Page

List help page of ls command with their option.

13. List Directory Information

With ls -l command list files under directory /tmp. Wherein with -ld parameters displays information of /tmpdirectory.

14. Display UID and GID of Files

To display UID and GID of files and directories. use option -n with ls command.

15. ls command and it’s Aliases

We have made alias for ls command, when we execute ls command it’ll take -l option by default and display long listing as mentioned earlier.

Note: We can see number of alias available in your system with below alias command and same can be unalias as shown below example.

To remove an alias previously defined, just use the unalias command.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.