In the previous posts, we learned what are commands and how do we use them to navigate through a Linux system. Now, let's go through some more commands that will help us in exploring the Linux System.
The first command we are going to look into is ls
command.
Wait. Didn't we already explore ls
command?
Yeah! We did explore ls
command briefly but now we are going to see the true power of ls
command.
1.ls
command
As we have seen, we can simply enter ls
to get a list of files and folders contained in the current working directory
Besides the current directory, we can use ls
command to list the files and folders of any directory like
In the above example, we first checked our current working directory using pwd
command and then we used ls
command to list all the files and folders of a directory named folder1 without even going inside folder1.
Isn't this awesome we did not even have to go inside a directory to list its files and folders. The fun doesn't end here we can even specify multiple directories.
In the above example, we can see that we have used ls
command to list files and folders of not just one but three directories.
Okay, so we can list files and folders of multiple directories what else?
Remember in the last post we went through the command structure and got to know something known as options. If you missed the last post I would suggest you go through it for better understanding.
Options are basically used to modify the behavior of the command.
So here we are going to explore some common options that are used with ls
command.
What can we do
- To list even the hidden files and folders
ls -a
allows us to list even the hidden files and folders.In the above example all the files and folders starting with .(dot) are hidden ones and we can still see them.
- To classify the files and folders
As we can see from example ls -F
allows us to classify files and folders where folders are indicated by a forward slash (/).
- To get output to reveal more detail
ls -l
allows us to get detailed information on files and folders.
- To get output to reveal more detail and make it more readable.
ls -lh
allows us to get detailed output in a more readable form, where h represents human-readable and l represents the long format.
- To display the output in reverse order
In the above example, ls -lhr
we have just reversed the output from the previous example, where r represents reverse order, h represents human-readable and l represents the long format.
- To Sort By file size
ls -S
allows us to sort the output on the basis of size.
- To Sort By last modified
ls -t
allows us to sort the output on the basis of last modified.
Now, these were some common ls options that are used to explore the Linux System.
After we list down all the files using ls
command what else do we need for exploring the Linux System?
What we need now is to find out what files contain.
Okay, so how can we do it?
2.file
command
The syntax for file
command
For finding out what type of file we are looking at we only need to call command file
along with the filename.
Let's take few examples for better understanding
- For a text file
In the above example, we can see that for a text file the command returns us the result of ASCII text.
- For an image
In the above example, we can see that for a image file the command returns us the result of the JPEG image data.
Now we know how to list files and how to find the type of file.The only thing that seems to be remaining right now is how to open a file
3. less
command
The less
command provides us a way to view text files in our terminal itself.
The syntax for opening a file using less
command
To open a file using less
we only need to call less
command along with the filename.
less provides us tons of functionality such as search a character, scroll up/down, etc.
Okay, so thatβs all the commands we need to know to explore Linux System.
I hope you understood the basics of exploration in Linux. Please, let me know if there are any questions.
Top comments (0)