Linux ls Command Tutorial With Examples – POFTUT

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 ls

Man page of ls command can be retrieved like below.

$ man ls
Man ls
Man ls

List Files

We can list files and folders simple without providing any parameter. This will list all files except hidden files those names starts with .

$ ls
List Files
List Files

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
List Files According To Modification Date
List Files According To Modification Date

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
Display One File Per Line
Display One File Per Line

Show Detailed File Information

We can get more details about files and folders with -l option.

$ ls -l
Show Detailed File Information
Show Detailed File Information
  • 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 Size Information Human Readable Format
Display Size Information Human Readable Format

Display Directory Information

We can list only directory with -d  option. It will not list files and directories under it.

$ ls -dl tmux
Display Directory Information
Display Directory Information

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
Reverse Order List
Reverse Order List

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 Hidden Files
Display Hidden Files

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 Recursively
Display Files Recursively

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 Files Inode Numbers
Display Files Inode Numbers

Display User Id (UID) and Group Id (GUID)

We can list user and group id of files according to their names

$ ls -n
Display User Id (UID) and Group Id (GUID)
Display User Id (UID) and Group Id (GUID)
  • 0 0 are user and group id of root
LEARN MORE  Linux ls Command Tutorial To List Files and Directories

Classification of Files with Colors

Coloring will easy viewed of the files and folders. We can colorize the ls command output with the --color=auto option.

$ ls --color=auto
Classification of Files with Colors
Classification of Files with Colors

Alias for ls

We can make providing parameters more practical. We can define alias for ls commands with parameters.

$ alias ll="ls -lh"
Alias for ls
Alias for ls
  • 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
List Files and Directories with / At The End
List Files and Directories with / At The End

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
Sort Files By Size
Sort Files By Size

 

Linux ls Command Tutorial With Examples Infografic

Linux ls Command Tutorial With Examples Infografic
Linux ls Command Tutorial With Examples Infografic

1 thought on “Linux ls Command Tutorial With Examples”

Leave a Comment