WriteBash - To list the files and directories in the current working directory, we use the
If on the Windows operating system, when you move to a specific folder, the files and subdirectories in it is automatically displayed for you to view. But for the Linux operating system (for the server) you need to use the ls command
Meaning of the command “ls”
ls command lets you list files or subdirectories contained in a directory. The use is quite simple, on the command line of linux, you just type
ls if you are standing in the directory that you need to list.
For example, as shown below, i’m in the
/etc directory of the system, i type
ls and all files or directories listed.
If you want to list the contents of a directory without looking at where you are, then add the path to the directory immediately after the ls command.
A few advanced uses of the “ls” command
The first is often used to list the contents of a folder and display the results in the latest time stamp at the bottom. Type the command as follows:
Command below with the parameters as follows:
- -l: use a long listing format.
- -t: sort by modification time, newest first.
- -r: reverse order while sorting.
The second case is to list the contents of the folder and display the results according to the latest timestamp at the top. Type the command as follows:
-a parameter: do not ignore entries starting with
If you look at the image below will see there are several folders with the directory name is a dot.
The third case is to list the contents of the folder and display the results by the size of the file or folder with the largest size at the top. Type the command as follows:
-S (s uppercase character) parameter: sort by file size, largest first.
ls -l -S
For more options of the ls command then you type the command below:
With this article, I hope you can understand how to use this command to list the contents of a certain folder, as well as how to use the parameters of the this command.If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.