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
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
Thanks for such good information
ReplyDeleteThank you Reshma Bhosale, I will try to improve more for better understanding.
DeleteWell explained.
ReplyDeleteThank You Yogesh Pawar
Deletevery good information.
ReplyDeleteThank you.
DeleteNice one
ReplyDeleteThank You.
DeleteNice explanation
ReplyDeleteThank You.
Delete