Working with Terminal in Linux - Part 1

learn to do basic operations in Linux using terminal like a pro

Working with Terminal in Linux - Part 1


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:

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.

  • 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 ):

  • 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:

    • 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 ).

  • 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 )

  • 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:

  • Let me explain each of the columns in the long form list ( ls -l ):

    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 ):

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

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

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.

  • 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:

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

  • 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 ).

    • 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 when it's released.

Thanks for reading this!

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

  • giving me a follow,

  • or by dropping a like,

Did you find this article valuable?

Support Anand Darshan by becoming a sponsor. Any amount is appreciated!