Using ls command in Linux
 

Using ls command in Linux

 

The ls command is a basic and one of the most frequently used commands in a Linux or Unix system. It is used to list files and directories of a filesystem. When used with certain options it displays a list of files and directories with very useful information.

Today we will discuss the usage of the ls command in Linux with some examples.

Syntax of ls command

The syntax of the ls command is given below –

ls [Options] [File]

To see a detailed list of options that can be used with the ls command execute the following command in your terminal –

man ls

Display the list of files and directories

When the ls command is used without any arguments it simply displays the list of files and directories under the current working directory.

ls

You can see the output in the image below –

How to display the file and directories in the long listing format

When ls command is used with option -l (lowercase L) it displays the files and directories in the long listing format. In long listing format output includes information such as file name, modified date and time, size, owner of the file, and its permission.

Use the following command to display the files and directories in long listing format –

ls -l

Now see the output of this command –

Print the output in reverse order

You can print the output in reverse order by using option -r with the ls command. Now use the following command in your terminal –

ls -lr

Note: While listing file or directories at some places such as /root you might need to have root permissions so you should use the sudo with the command

How to view the hidden files and directories on Linux

A hidden file or directory starts with . (dot) in its name. To display the list of all files and directories including the hidden one use option -a with ls command.

ls -a

Or use the following to display all files and folders in long listing format –

ls -al

Display all the files in a human-readable format

When you use option -h with ls command it will display output in a human-readable format in which it displays the size like 500K, 2M, 1.5G, etc.

Now execute the following command –

ls -lah

The output will look like this –

Listing subdirectories recursively

If you use -R with the ls command it will display subdirectories recursively. Now use the following command –

ls -R

Conclusion

For more usage of ls see its manual page. Now if you have a query then leave it in the comments below.

Previous [lubuntu] Second HDD write protected ... :-((
Next Problem to install WINE
 

About author

You might also like

Commands 0 Comments

Using systemctl command in Linux

The systemctl command in Linux is responsible for controlling a widely adopted “systemd” init system and service manager. The init is the first process that starts when you power on

Commands 0 Comments

Linux TAR Command

This post was last updated on May 27th, 2020 at 05:18 pmContents1 create:2 extracting:3 testing/viewing:4 Errors:5 Spaces in your filenames? create: tar -cvf mystuff.tar mystuff/ tar -czvf mystuff.tgz mystuff/ extracting:

Commands 0 Comments

Using dig command in Linux

The dig (stands for Domain Information Groper) command in Linux is used to find and display the domain information. It performs DNS lookup and fetches queries from name servers. This

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply