Linux ls command with examples

In this article, we will see Linux ls command with examples.

ls is the most used command in the Linux operating systems. ls is used to display all files and directories present in the given directory.

run man ls on terminal to complete information about ls command.

Linux ls command with examples:

1. ls with no option:

This will display all files and directories according to alphabetical order of names.

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.

Example:

ls

Linux ls command with examples

2. List Files in Reverse Order

This command displays all files and directories in reverse of alphabetical order in given diretory.

ls -r

3. List hidden files
Display all files including hidden file starting with . and ..

ls -a

4. ls -F
Using -F option with ls command, will add the / Character at the end each directory. Displays all files by type.

Types are displayed with /,*,@
Where

directory–> /
executable–> *
link file–> @

ls -F

5. ls -l
Displays long listing of files. It shows file or directory, size, modified date and time, file or folder name and owner of file and its permission.

Its alpha character ‘l’. But not number ‘one’.

ls -l

6. ls -t

To display all files based on last modified date and time. Most recent is at top and old are at bottom.

ls -t

7. ls -R
R means recursive. It will list all files and directories including sub directory contents also. By default ls will display only direct content but not sub directory contents.

ls -R

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

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

ls -lh

9. Reverse Output Order with -ltr option

With combination of -ltr will shows latest modification file or directory date as last.

ls -ltr

10. Sort Files by File Size
with option -s, we can sort by file size, largest first.

ls -S ls -lS

Linux ls command with examples

11. ls -i
To display all files including node number.

ls -i

12. Display all files from a given directory

We can use ls -l /directory_name to get list of files and sub directories.

ls -/ /scripts

13. Get Complete options

man ls