Exploring Linux System
Tags: linux, ubuntu, beginners, computerscience
Published: 2020-05-06 06:07:11

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](https://dev-to-uploads.s3.amazonaws.com/i/vhcm5mkdpbj6ybylux9q.png)

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

![ls command with different path](https://dev-to-uploads.s3.amazonaws.com/i/kqcrlv96xczp3fh4pi0o.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/tl13grwponmcomfzp998.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/b3k3f9vks48bm0vj089c.png)
`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](https://dev-to-uploads.s3.amazonaws.com/i/hsox835nj9o0td85omft.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/g45pek10r20l6cv62hq1.png)

`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](https://dev-to-uploads.s3.amazonaws.com/i/p0ahw9tza93cwsvt2qr2.png)

`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](https://dev-to-uploads.s3.amazonaws.com/i/hhkqebcw1dav828it6lg.png)
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](https://dev-to-uploads.s3.amazonaws.com/i/b3fozlsr24ao1dgjrki2.png)

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

- To Sort By last modified 

![ls sort last modified](https://dev-to-uploads.s3.amazonaws.com/i/bxcrqh6mpsyel564x9ob.png)

`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](https://dev-to-uploads.s3.amazonaws.com/i/q2nd758jrp3bl1xgz70p.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/91k33zfu447zdofzqr7s.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/ci1pgfo9smum9sl9tmxr.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/703hfgpny9e4hg1cnfng.png)

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

![less commands](https://dev-to-uploads.s3.amazonaws.com/i/hbquo8yy0ihb5vpdsfq9.png)

**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.