ls command is one of the mostly used command among all the commands. ls stands for list. It helps in listing the files and directories in the current working directory. So let’s begin with how to use ls command in Linux
In this post, We will learn all the day to day usage of ls command that can help you to use your server properly.
Usage No. 1 is to use the ls command without any option that would simply show the list of items in that particular folder.

Usage No. 2 is to use the ls command with -l option that will show the long list of that particular folder. Another way to do same thing is by ll command. It will also show details like read-write permissions, owner, size etc.

Usage No. 3 is to use the ls command with -a option that will list all the items including hidden items that is known by a dot in front of the File/Directory name.

We can also do ls for any directory that is not our working directory. For example, my working directory is /root and I want to see the list in /var. I can directly do ls /var to see the list of items in /var directory.
Usage No. 4 is to use the ls command with -sh option that will list the items with size in the human readable format. It is one of the important option when we need to know the size of our directory and files.

ls command can be used for so many more different options but you can learn about more options with the help of man pages. If you do not know about that then click on the link.
If you are new and want to download CentOS then click on the link.
For Queries, Please check our FAQ on how to use ls command in Linux.
Q. What is the ls
command?
A. The ls command is used to list files and directories in the current working directory or specified directories. It provides a way to view the contents of a directory in a readable format.
Q. How do I use the ls
command?
A. Simply type ls and press Enter to list the files and directories in the current directory. You can also specify a path to list the contents of a different directory, e.g, ls /path/to/directory.
Q. How can I list files in a human-readable format?
A. Use ls -lh. The -l option provides detailed information and -h makes file sizes human-readable.
Q. How do I list directories only?
A. You can use ls -d.
Q. How do I sort files by modification time?
A. Use ls -lt to list files sorted by modification time, with the most recently modified files first.
Q. How can I display hidden files?
A. Use ls -a to include hidden files in the listing. Hidden files start with a dot (e.g. .hiddenfile)
Q. How do I list files with detailed information?
A. Use ls -l to get a long format listing that includes permissions, number of links, owner, group, size and timestamp.
Q. Can I use ls
for multiple directories?
A. Yes, you can specify multiple directories or files. For example, ls /dir1 /dir2 will list the contents of both dir1 and dir2.
Q. How can I list files and directories recursively?
A. Use ls – R to list all files and directories recursively from the specified directory.
Q. How do I get a listing of files with permissions and ownership information?
A. Use ls -l. This provides detailed information about each file including permissions, ownership and size.
Discover more from Root Learning
Subscribe to get the latest posts sent to your email.
NICE for the new student like me.