DEV Community

yash sugandh
yash sugandh

Posted on

Exploring Linux System

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

ls command

Besides the current directory, we can use ls command to list the files and folders of any directory like

ls command with different path

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.

ls command 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 command all
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

ls command classify

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 command long

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 command human 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

ls command reverse
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 sort size

ls -S allows us to sort the output on the basis of size.

  • To Sort By last modified

ls sort 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

file command syntax

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

file command text

In the above example, we can see that for a text file the command returns us the result of ASCII text.

  • For an image

file command 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

less command syntax

To open a file using less we only need to call less command along with the filename.

less commands

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)