Let's face it, you’re here because you saw the word dummies and felt at home. Say no more — You’ve got company!
Through this short article, you’ll essentially learn what Linux is, and some simple commands for you to hit the ground running.
What is it?
Linux is an Operating System just like Windows or macOS. Simply put, an Operating System manages the communication between your software and your hardware.
The Operating System consists of a number of pieces stacked on top of one another starting from:
- The Hardware layer — This consists of all the external devices like your CPU, RAM, Hard Disk Drive, and other edge gadgets.
- The Kernel — This is a computer program that is the core of the operating system. It deals with the hardware layer and controls and manages the entire system.
- The Applications — These reside over a Graphical User Interface which users can access easily.
- The Shell — In simple words, Shell is a software that takes the command from your keyboard and passes it to the Kernel. Linux provides some terminal emulators, as in, an interface through which the user can interact with the Shell.
You can think of the terminal as a Genie which executes your commands. The terminal can be viewed as a direct replacement to the Interface that we are used to in our daily lives. For instance, say in our Windows machine we need to open a folder, for this, we have an interface with shows an icon that resembles a folder on which we click to navigate inside it. Instead, in Linux OS, we enter a command in a Genie called the Terminal, which does the same task of navigating to a folder. Alakazam!
Now that you have a basic understanding of Linux and what the terminal is, let’s look at some commands which you will be using frequently as a beginner.
Here are a few commands followed by an example of their usage and its output. Make sure you try these out as we go along.
echo— To print some content on the terminal.
$ echo “hello”
pwd— shows the present working directory you are on.
cd— used to change directory and go to the desired directory. We can use cd followed by the path of the directory we wish to go to. After running the below command we would end up in the Downloads folder.
$ cd /home/admin/Downloads/
ls— lists all files and folders in the particular directory. For instance, if you are in the Downloads folder, this command will show all files and folders inside it.
We can also use certain flags available with this command like the one shown below which lists the files in your present directory in long-form. You can check out some more using the man command described ahead.
$ ls -l
man— prints the name and description of a particular command. For instance, the command
man lsshown below shows a description of the ls command and its various options.
$ man ls
This command opens a Manual Page. To exit this page and return to the prompt, you need to press ‘q’.
clear— clears the terminal and brings the command line on top of the terminal.
exit— closes the terminal window.
Some useful tips💡
TAB while typing a command or file name. This auto-completes the command/file name which we wish to type and also shows the other possible commands available.
▹ Instead of typing out the command you already gave earlier, use the
DOWN arrows to get them back to your prompt.
▹ In case you are stuck in the terminal and it is asking for any further input, you can get out by pressing Ctrl + c.
Now that we’ve got our hands dirty, let’s go ahead and learn some important commands which we would use often.
This stands for Create, Read, Update and Delete. These are the four basic operations on any computer. These operations can be performed on a database level or a file level. For instance, in Google drive, we create, read, update or delete any data. Here, we are basically performing CRUD on Google Drive’s Server at a database level. Similarly, we can do these operations on a file level. Let's explore how:
CRUD operations on file and folder levels
★ Create Operation:
a. Create a file — we can use the
touch command to create a new file. This command takes in one argument which is the name of the file. A new text file called hello-world will be created in the current directory we are on.
$ touch hello-world.txt
b. Create a folder — the
mkdir command is used to create a folder. It stands for make directory. This command takes in one argument which is the name of the folder we wish to create. On giving the below command a new folder called Unix will be created in the present directory location.
$ mkdir Unix
★ Read Operation:
a. Read a file — we can read a file using commands like
vim which can be executed as shown below.
$ nano hello-world.txt$ vim hello-world.txt
nano command opens this text file wherein we can add some content to it and save it by pressing
Ctrl + x followed by
y and Enter.
vim command is similar, wherein we start typing some content after pressing
i and to save this file we need to press
:wq! and hit Enter.
If we wish to find a specific text in the file, we can use the
grep command. This stands for ‘Global Regular Expression Print’ and can be used as shown below:
$ grep 'how' hello-world.txt
Hey, how are you!
grep can also be used with the Pipe, which is a command used to join two commands as shown below:
$ cat hello-world my-dog.txt | grep 'are'
Hey, how are you!
Dogs are the best! Man's best friend for a reason! Aren't the
cat command is used to concatenate the two files and print their output in the terminal.
b. Read a folder — To read contents in a folder we can use the
cd command to navigate inside the required folder and then use the
ls command to view all files/folders inside it. Both these commands are discussed in this article earlier.
★ Update Operation:
a. Update a file — to update a file with some content we can use the echo command as shown below:
$ echo "I am fine" >> hello-world.txt
echo appends the line only to the end of the file.
b. Update a folder — Although there is no direct command to update a folder, we can achieve this using the move command as shown below:
$ mv Unix/ Learn-Unix/
This command renames the Unix folder. We can see the same content of the Unix folder inside the Learn-Unix folder now.
We can also use the copy command to move files/folders. Using the command below we have copied the file to the Documents folder.
$ cp hello-world.txt /home/admin/Documents/
★ Delete Operation:
a. Delete a file — to delete a file we use the remove command as shown below.
$ rm hello-world.txt
b. Delete a folder — to delete a folder we can use the remove directory command as shown below:
$ rmdir Unix/
In case the directory is not empty, this command will not work. In that case, we can use the following:
$ rm -r Unix/
In this command
-r is used to recursively delete all files in the folder and eventually the directory itself.
With this, we wrap up an introductory session on the basics of Linux with some handy commands. I recommend you try these commands out to get a firm handle on it.