An introductory guide to Linux CLI
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:
Navigating 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.
mark@test:~$ 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.
mark@test:~$ 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:
mark@test:~$ cd Directory2 mark@test:~/Directory2$ ls mark@test:~/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.
mark@test:~/Directory2$ cd .. mark@test:~$ rmdir Directory2 mark@test:~$ 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…
mark@test:~$ 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.
mark@test:~$ ls Directory1/ ImportantFile.txt mark@test:~$ rm Directory1/ImportantFile.txt mark@test:~$ rmdir Directory1/ mark@test:~$ ls Desktop Documents Downloads Music Pictures Public Templates Videos mark@test:~$
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 :
mark@test:~$ mkdir WorkDir mark@test:~$ touch WorkDir/WorkFile mark@test:~$ 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:
mark@test:~$ nano WorkDir/WorkFile
The 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.
- 2020 A year in review for Marksei.com - 30 December 2020
- Red Hat pulls the kill switch on CentOS - 16 December 2020
- OpenZFS 2.0 released: unified ZFS for Linux and BSD - 9 December 2020
Recent Comments