Skip to main content

Linux Command Line Tutorial For Beginners - ls command

ls is a Linux shell command that lists directory contents which may be files or directories.
First of all lets open Terminal, Alt+Ctrl+T
ls command uses following syntax:

         ls [option] [file or directory name]



if we give simple ls command it will show us all directories and files present in home directory, as when we open terminal by default we are in home directory.

Now if we want to see what is in Downloads directory then we simply give command as:

                         ls Downloads

Note one thing i.e., command line is case sensitive so we should write name of directory or file as it is.


In same way you can able to see contents of any directory.

If we want to see content of root directory then we will write command as:
As we know / is called as root directory.

                                   ls /



If we want long information of files or directory present in particular directory then we will write command as:

                                   ls -l

This will give information regarding date of last modified, Size, Rights for files or directories. 



Now you may have question regarding what is drwx, -rw, -xr ?
These are the rights for user separated by 
' - '
d means Directory, r means Read, w means Write, xr means Execute and read again, and only x means Execute.
1st block is for user right, 2nd block is for group right, and at last 3rd block is for others.

Now another command for showing hidden files is:
                                                    
                                   ls -a



You can see that all hidden files are starts with . (dot) and they are not visible using GUI.

Now if you want to short files according to size then we will give command as:

                                   ls -lS



Now you can see that file which have highest size is on the top.

Up to now we have seen how to use ls command, now we will see how to save result of any command in particular file.

We will use command as:

ls [option] [file name or directory] > [name of file where you save the output]

Remember one thing if we are going to save a file which doesn't even exists then it will create file of that name and save contents whichever we are providing.



Here you can see that one text file is created and named it as text.txt



These all are the basic commands related to ls but there are lots of flags are available along with ls you can see these all flags by using command:

                              man ls



 For getting out from man command simply strike d key.

In our next part we will learn how to use cat command in detail.

Thanks for reading my blog.

If you have any suggestions or feedback then simply put comment or you may contact with me.

Contact Details:
Phone: +91-8208826234
E-mail: shivampawar1038@gmail.com

Comments

Post a Comment

Popular posts from this blog

Linux Command Line Tutorial For Beginners - Introduction

Hi Friends, Welcome to Blog , Welcome to Linux . Now first question you may ask yourself why we should learn command line, even if we have GUI ? So, Simple answer is that GUI ( Graphical User Interface ) is helpful in many task but not useful in all task, and when you learn command, you will observe that you are able to do your day to day task or any task related to programming much faster that you can do with GUI . By using command you can able to see what happening in a background when you given a something task. Before dive into the world of Linux you should know two terms i.e., Shell and Terminal. Now what is Shell? Shell is a simply a program that takes inputs from the keyboard and gives that to the operating system to perform task.It is also called as CLI ( Command Line Interface ), Now the second term is Terminal, terminal is tool which is used to pass a shell command, this is a program that open up a window and lets interacts with shell. There are different operating...