Linux ls command
In Linux, command line syntax “ls” stands for list. List command (ls) show the full list or content of your directory.
List all the files and folders.
ls and press the enter key. The whole content will be shown.
atulhost@ubuntu:~$ ls Desktop Documents Downloads Music Pictures Videos
List all the files and folders, including hidden ones.
Just ls command will show you all the files and folders, as there could be much hidden stuff. If you want to list those all the hidden files too, just use the syntax
ls -a where flag a stands for all.
atulhost@ubuntu:~$ ls -a . .. .cache .mozilla .thunderbird Desktop Downloads Music Documents Pictures Videos
In the above results, the single full stop means null operation, and double full stop means previous directory.
List the directory in detailed view.
Now, what if you want to list the directory with details. Simply use syntax
ls -l where flag l stands for long.
atulhost@ubuntu:~$ ls -l total 20 drwxr-xr-x 2 atulhost ubuntu 4096 Jan 01 12:00 Desktop drwxr-xr-x 4 atulhost ubuntu 4096 Jan 01 12:00 Documents drwxr-xr-x 8 atulhost ubuntu 4096 Jan 01 12:00 Downloads drwxr-xr-x 2 atulhost ubuntu 4096 Jan 01 12:00 Music drwxr-xr-x 2 atulhost ubuntu 4096 Jan 01 12:00 Pictures drwxr-xr-x 2 atulhost ubuntu 4096 Jan 01 12:00 Videos
In the above results you can clearly read, there are total 20 files in the directory, folder permissions, file counts, user and owner details, size, date-time of creation, and finally name of the folder in a detailed view.
Similarly, I have made a list of all list flags followed by their descriptions.
|In Linux, hidden files start with . (dot) symbol and they are not visible in the regular directory. The (ls -a) command will enlist the whole list of the current directory including the hidden files.|
|It will show the list in a long list format.|
|This command will show you the file sizes in human readable format. Size of the file is very difficult to read when displayed in terms of byte. The (ls -lh) command will give you the data in terms of Mb, Gb, Tb, etc.|
|If you want to display your files in descending order (highest at the top) according to their size, then you can use (ls -lhS) command.|
|It is used to display the files in a specific size format. Here, in the place of [SHOW SIZE IN] you can assign size according to your requirement. Use: K = Kilobyte, M = Megabyte, G = Gigabyte, T = Terabyte, P = Petabyte, E = Exabyte, Z = Zettabyte, Y = Yottabyte.|
|It is used to display only sub-directories.|
|With this you can exclude column of group information and owner.|
|It is used to print group ID and owner ID instead of their names.|
|This command is used to print list as colored or discolored.|
|This command prints the index number if file is in the first column.|
|It is used to identify the directory easily by marking the directories with a slash (/) line sign.|
|It is used to print the list in reverse order.|
|It will display the content of the sub-directories also.|
|It will group the files with same extensions together in the list.|
|It will sort the list by displaying recently modified filed at top.|
|It gives the contents of home directory.|
|It gives the contents of parent directory.|
|It checks the version of ls command.|
I hope this article help you to understand list command.