The ls
command in Linux is used to list the files of a given directory.
The
ls
command comes as part of the GNU Core Utilities package, available on all Unix-like operating systems.
The ls
command has many functionalities. It accepts different flags or arguments in accordance with the required functionality.
This shot will go through the most frequently used flags of the ls
command.
The ls
command is used without any arguments to list all the files and folders in the terminal’s current directory.
To list all the files and folders in a particular directory, the path of this directory is input as the first argument to the ls
command.
The /
argument is used to list all files and folders in the root directory.
The ..
argument is used to list down the files and folders in the parent directory of the current directory.
The ~
argument is used to list all files and folders in the home directory.
The -R
argument is used to recursively list down all the folders and files in all the directories and sub-directories of the system.
The -lS
flag lists down folders and files in sorted order (according to size).
The -a
argument is used to list down any hidden folders or files.
In the example below, we first use the ls
command without any argument to list all the files and folders in the current directory.
Subsequently, we input the path of the bin
folder and list all the folders and files in it.
Lastly, we use the -R
argument of the ls
command to list down all the files and folders of the system. The contents of all the sub-directories and directories are fetched recursively.