An introductory guide to Linux CLI

linux permissions security text hash crypt encryption decryption cryptography

The Linux Command Line Interface is easily the most powerful tool available on Linux. Learning the Command Line may seem daunting at the eyes of the beginner, but it is a fundamental skill for Linux System Administrators.

Get into the terminal

The first thing to do to get started is to open a terminal. Most likely you will already have it installed within your system. Just open your menu and search for an entry named terminal or konsole. Now you will be facing the terminal and here you will learn how to use the command line:

Ubuntu TerminalNavigating through files

The first thing you need to do is learn how to move through the filesystem. In order to do so, you need only three commands: pwd , ls and cd . With pwd you get the terminal to Print your Working Directory.

[email protected]:~$ pwd
/home/mark

Now that you have a better understanding of where you are, you will want to know what is there in the directory, that’s the purpose of ls : to list the content of the current directory.

[email protected]:~$ ls
Desktop     Directory2  Downloads  Pictures  Templates
Directory1  Documents   Music      Public    Videos

Here you have the list of files and directories inside your working directory. Chances are they will be marked differently (in my case they were coloured) but it really depends on your terminal/shell. Now that you have the list, you suddenly can’t remember what is the purpose of Directory2. You decide to inspect its content by changing directory:

[email protected]:~$ cd Directory2
[email protected]:~/Directory2$ ls
[email protected]:~/Directory2$

You used cd to navigate into Directory2 and ls to inspect its contents. To your surprise, you discover Directory2 is empty!

Managing directories and files

You decide to return to the parent directory and remove Directory2.

[email protected]:~/Directory2$ cd ..
[email protected]:~$ rmdir Directory2
[email protected]:~$ ls
Desktop     Documents  Music     Public     Videos
Directory1  Downloads  Pictures  Templates

The two .. point to the parent directory of your current directory, while rmdir enabled you to delete Directory2. Now you decide to remove Directory1 too, but…

[email protected]:~$ rmdir Directory1/
rmdir: failed to remove 'Directory1/': Directory not empty

The directory is not empty! So you decide to list the files inside Directory1 and remove them one by one.

[email protected]:~$ ls Directory1/
ImportantFile.txt
[email protected]:~$ rm Directory1/ImportantFile.txt 
[email protected]:~$ rmdir Directory1/
[email protected]:~$ ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
[email protected]:~$ 

As you can see Directory1 contained ImportantFile.txt and you removed it through rm . BE CAREFUL: rm is an extremely dangerous command and a mistype can cause serious damage to your system. Be careful!

Now you need to create a directory for your important project and create three files inside of it: the commands are mkdir and touch :

[email protected]:~$ mkdir WorkDir
[email protected]:~$ touch WorkDir/WorkFile
[email protected]:~$ ls WorkDir/
WorkFile

This way you created the WorkDir and the WorkFile inside of it, all using CLI!

The Nano editor

One of the most interesting thing you can do in the CLI in your beginner phase is edit plain-text files using a text-editor. Though you can do it also using a GUI, CLI editors are usually faster and do not require loads of packages to be installed. However they require you to learn a few more things. The editor I want to show you is called nano and it is quite simple (opposed to other editors such as vi). Not all distributions include it by default, you should learn online how to install it. To run simply do:

[email protected]:~$ nano WorkDir/WorkFile

Ubuntu nano text editorThe interface may be intimidating but trust me, it is not. All the commands are just down there! Remember the ^ represents the Ctrl key. So to exit you would do Ctrl+X . You can write and modify the file and when you’re done just type the exit shortcut and confirm you want to overwrite. Pretty simple isn’t it?

What’s next?

This was a pretty basic introduction to the Linux CLI for amateurs. If you want to get serious and learn the Linux CLI to become a pro, you should start learning about file permissions and the associated commands.

 

Image courtesy of r2hox.

Image courtesy of mark | marksei

The following two tabs change content below.
The IT guy with a little boredom look in his eyes, fond of computers since forever he now works as a freelancer in the IT and shares his experiences through this blog.

You may also like...