# Working with Terminal in Linux - Part 1

**NOTE: *THE BLOG TARGETS ABSOLUTE BEGINNERS***

## What will you learn?

You will learn the following in Part 1:

* How to list contents of directories using the ls command efficiently.
    
* How to change directory ( cd ) and its variant.
    

And following in Part 2:

* How to copy, and cut ( or move ) stuff.
    
* Different options to create and delete ( remove ) files and directories ( folders ).
    
* Concluding
    

## Let's get started:

![](https://media.giphy.com/media/ppdJSbkKj25NvdxFQo/giphy.gif align="center")

Open a terminal first. **Ctrl + Alt + T** is the hotkey combination that works in a few Linux operating systems. It doesn't work in all OSs though.

---

# Working with the ***ls*** command:

---

1. **ls** command is used to `list` the contents of the directories.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693533082038/6a6e5f36-9e67-4d24-b62c-9a79dc43cc99.png align="center")

* We have a total of 9 contents in the current directory from Desktop to Templates.
    
* All of these are directories, but how do we know if the content listed is a directory or something else? Don't worry, we'll talk about it in the ls options section.
    

To know the current directory that you're working in, we can use the command **pwd** ( `print working directory` ):

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693533222644/01afaf8f-0d8e-44b0-9eff-10c5f493a1cd.png align="center")

* pwd gives us the full path of the current directory which is "*/home/anand*"
    

1. Now, if we wanted to list the contents of a directory without actually being at its absolute path, **then we can use ls with its full path to get the content list**:
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693534443668/40672bc0-27dc-4d8e-9af1-fd0f108b8183.png align="center")
    
    * But, we have two types of paths that we can use;
        
        * One is the **Absolute path** ( Full path to the directory ) and,
            
        * The other one is the **Relative path** ( relative to the current directory ).
            

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693535061903/fd19cc33-82ca-4275-98a2-fec69a4af3ba.png align="center")

* We now know the basic workings of ls. Let's now learn its few important options.
    

### Basic Options ( switches ) of the ls command:

* Switches or options extend functionality and give us more control over the way a command ( or CLI utility ) works.
    
* How? Just observe how ls works with its switches and you'll get it.
    

> ### ls -a ( -a option for all )
> 
> ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693536078906/2b50cd91-0264-4cb2-a5e4-49f8dc93a0de.png align="center")
> 
> * Notice how we now have many more contents in the list than the ls command without -a option.
>     
> * This ls -a simply means `List all` the contents of the directory.
>     
> * Here files and directories starting with "." are hidden contents and are only listed if forced to. This switch "-a" forces the ls command to list even the hidden contents.
>     
> * That is why we have more content listed here.
>     

---

> ### ls -l ( -l for long listing )
> 
> * This option lists the content in a long format, which shows a lot of other details for each file and directory:
>     
> 
> ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693546353295/85c8f708-859a-45c3-ae88-bacbe7ccf083.png align="center")
> 
> * Let me explain each of the columns in the long form list ( ls -l ):
>     
>     ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693546813699/1ae43b89-3098-477a-96fe-532d6ef5fca8.png align="center")
>     
>     Also, in permissions, whenever there's a d in the beginning, it means the content is a directory:
>     
>     * All of the contents in the list are directories except one ( file.txt ):
>         
>     
>     ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693547040687/30d345fa-7309-45b0-9a8e-e8903ccdfde5.png align="center")
>     

Now you can even combine the two options ( -a and -l ) to list hidden content as well as list them in long format:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693547175489/3e1d6817-d35e-4919-811f-13cbfa61270a.png align="center")

That's enough about ***ls***. Let's move on to the next one, shall we?

---

* It's a checkpoint, go grab a cup of coffee or something.
    
    ![Congrats Frend | CONGRATS ON MAKING IT THIS FAR; TAKE THIS GLASS OF WATER :) | image tagged in memes,leonardo dicaprio cheers | made w/ Imgflip meme maker](https://i.imgflip.com/7i57ct.jpg align="center")
    

---

# Working with the ***cd*** command:

---

cd command is used to `change directories` and is available in both Linux and Windows. We are talking about it in the context of Linux here.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693548254011/edde147d-8dd6-40c6-a92f-8168d1cd7621.png align="center")

* Our current working directory is /home/anand but using cd we changed the directory to tutorial.
    
* Now our pwd ( current working directory ) is **/home/anand/tutorials**.
    

We can use the relative or absolute path here same as ls:

* The example above was the relative one.
    
* Let's now use an absolute path of a directory with cd:
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693548730000/759a106f-552d-44fe-ae12-446c1deb5ce4.png align="center")
    
    * we used an absolute path "/var/log" and changed our directory from /home/anand to the /var/log directory using cd.
        

### Navigating to parent and previous directories by using special character sets with cd ( .. and - )

> ### Navigate to a parent directory
> 
> * cd .. lets us navigate to the parent directory of the current directory.
>     
> 
> ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693549200133/1b1a5067-a25a-45cf-bc29-5560c8e04c65.png align="center")
> 
> * As you can see, we move up a directory ( parent directory ) whenever we use the command **cd with a double dot "..".**
>     

---

> ### Navigate to the previous directory
> 
> * When we use cd with a hyphen ( - ), we move to the previous working directory ( previous doesn't mean parent ).
>     
>     ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693549610264/46561de7-dacd-4dbf-ba86-76545d492f60.png align="center")
>     
>     * First, our directory was "/home/anand". We changed it to "/var/log"
>         
>     * Now when we use "cd -", it brings us back to the previous directory which was /home/anand.
>         
>     * If we use this command again, it will bring us back to the directory that we're in before the current one ( /var/log ).
>         
>     * This allows us to move back and forth between two directories without needing to write entire paths, letting us save some time. Makes our workflow faster.
>         

We are done with cd command, You might wanna take a break for now and then consider coming back to [Part 2 of the article](https://blog.anandxdarshan.tech/working-with-terminal-in-linux-part-2) *when it's released*.

---

![](https://media.giphy.com/media/3oz8xAFtqoOUUrsh7W/giphy.gif align="center")

---

# Thanks for reading this!

### If you like the way I write, consider supporting me by

* #### giving me a follow,
    
* #### or by dropping a like,
