Linux ls Command Tutorial With Examples
Linux operating system provides a lot of different functionalities with different tools and commands. ls is the most used command in linux. ls is the arm and leg of Linux system administrator. ls provides a lot of different functionalities with different options.
Man page of ls command can be retrieved like below.
$ man ls
We can list files and folders simple without providing any parameter. This will list all files except hidden files those names starts with
List Files According To Modification Date
-t parameter make listing according to their modification date. REcently modified file will be listed in the upper side
$ ls -t
Display One File Per Line
We can set 1 file will be listed in single line. This is generally useful for providing file list as an input into other commands or applications.
$ ls -1
Show Detailed File Information
We can get more details about files and folders with -l option.
$ ls -l
- drwxr-xr-x is permission information
- root root is user and group information. It is related with permission
- 4096 is the size in byte . Folders have same size
- Oct 6 12:08 is the modification date
- Amsterdam is the file or folder name
Display Size Information Human Readable Format
We see that size is in byte format we can change is MB,GB format according to its size
$ ls -lh
Display Directory Information
We can list only directory with -d option. It will not list files and directories under it.
$ ls -dl tmux
Reverse Order List
We can list files and folders according to their names, modification date. But we can reverse order with -r parameter
$ ls -ltr
Display Hidden Files
Linux world hidden files are pretended with a point before their name. By default ls do not list these files. We can list them too with -a
$ ls -l -a
Display Files Recursively
We can display files recursively with -R parameter. Recursively means we will list folders and their contents and this goes to the deepest path.
$ ls -R
Display Files Inode Numbers
Inode is file system related information about files and folders. Inodes generally do not needed daily usage but sometimes it can be important.
$ ls -l -i
Display User Id (UID) and Group Id (GUID)
We can list user and group id of files according to their names
$ ls -n
- 0 0 are user and group id of root
Classification of Files with Colors
Coloring will easy viewed of the files and folders. We can colorize the
ls command output with the
$ ls --color=auto
Alias for ls
We can make providing parameters more practical. We can define alias for ls commands with parameters.
$ alias ll="ls -lh"
- alias create ll command
- ls -lh is the actual command where it will be called ll is issued
List Files and Directories with / At The End
To in scripts or other types directories and files can be listed with / at the end with -F
$ ls -F
Sort Files By Size
One of the most useful option of ls command is sorting files according to their sizes. This will list bigger files first and then decreasingly.
$ ls -lS