Linux has been around since the mid-90s and now serves as the most widely used operating system in the whole world. You can find this OS on your smartphones, computers, servers, cars, home appliances and many more.
This is one of the most popular platforms on the planet. Linux is mostly used in servers and more than 90% of the internet we have today is powered by Linux servers.
That’s a long way it has come from the 90s.
Linux is an open source and free software which makes it possible for anyone to make changes to the code and redistribute it under a different name. Some of the most famous Linux based operating systems are:
- Kali Linux
- Red Hat Linux
Bottom line is Linux is everywhere! So sooner or later you will come across this OS. Linux is mostly used without a GUI (graphical user interface) and this results in absolute beginners to get lost going about it.
However we did the research and compiled the 40 most basic commands that will get you to master the Linux environment. To start our journey we need to get familiar with the “terminal” or “shell”.
What is Linux Shell?
In the simplest terms, this is the place which receives the commands from the user, gives it to the operating system and shows the output. Most Linux distributions come with a CLI (Command line interface) and you use the terminal/shell to input the commands.
Note that there are Linux distros that come with a GUI also but this tutorial is dedicated for the beginners who wants to familiarize with the Linux command line.
Now let’s open the Terminal and let’s get started with the commands.
Note that the Linux shell is case sensitive so you should be careful when entering commands.
Basic Linux commands
1. PWD command
The pwd command will show you the current working directory (also known as folder) you are in. It will show the absolute path with all the directories. An example is /root/folder1
2. LS command
The ls command is used to show all the content inside a directory. The default settings is to show the contents of the directory you are in.
If you want to see the content in other folders you should type the folder path after ls. For example ls /root/folder1/books to view the files inside books folder.
The ls command has many variations:
- ls –R : List all files in sub directories
- ls –a : List hidden files
- ls -al : List detailed information of files and directories (permissions, size, owner, etc.)
3. CD command
The cd command is used to navigate between files and folders. For this to work you will need to type the full path or the name of the directory (depends on your current directory).
There are some shortcuts to help you navigate quickly:
- cd .. (with two dots) to move one directory up
- cd to go straight to the home folder
- cd- (with a hyphen) to move to your previous directory
4. MKDIR command
You can use the mkdir command to create new directories. For example to make a directory called pictures you can type mkdir pictures.
Here are some tips on using the mkdir command:
- To generate a new directory inside another directory. Use this format mkdir pictures/europe
- Using p to create directories in between two existing directories. Here’s an example: mkdir –p pictures/trips/Europe
5. RMDIR command
If you need to delete a directory, use the rmdir command. However, rmdir only allows you to delete empty directories.
6. RM command
You can use the rm command to delete files. However if you want to delete all the files in a directory use rm –r.
7. TOUCH command
The touch command is used to create empty files directly from the command line. For example: touch docnew.txt will create a new text file with the name ‘docnew’.
Also you can create files in different location by specifying the path: touch /home/1gbits/docs/mywebsite.html which will create html file under the docs directory.
8. FIND command
The find command is used to search for files and directories. The find command is used to find files within a given directory.
An example is: find docnew.txt
9. GREP command
The grep command lets you search for all the text in a given file. For example, grep dummy testdoc.txt will search for the word “dummy” in the notepad file. Lines that contain the searched word will be displayed highlighted.
10. HEAD command
The head command will make your life much easier when going through documents. This command is used to view the first lines of any text file. By default it will show the first 10 lines of text.
11. TAIL command
This one has a similar function to the head command, but instead of showing the first lines, the tail command will display the last ten lines of a text file.
12. DIFF command
The diff command compares the content of two files line by line. This is useful when you need to make program alterations, instead of writing the entire code again.
An example would be diff code1.txt code2.txt
13. MAN command
There are a lot of commands in Linux and it’s normal that we don’t remember what each of them does. This is where the man command comes to help. It shows the manual pages of the command. For example, “man ls” shows the manual pages of the ls command.
No matter command, with the man command you can know everything about each of them.
14. MV command
The mv command has two functions:
- To move files
- To rename the files
In order to move a file you can type mv test.txt /home/1gbits/document. As shown in the example you should set the name of the file that needs to be moved and then to set the path.
To rename files you can use mv file1.txt file5.txt. The name of the file will be changed to file5.txt
15. NANO command
The nano command is used to create and edit text files. This is an easy to use command line text editor which includes all the basic functionalities of a regular text editor.
16. SUDO command
The sudo command will let you perform tasks that requires root privileges. However it is not advised to use this command for daily usage because if an error will be made it will be hard to make it right.
There are a lot more commands that are out there but we believe that with these simple codes you can start getting familiar with the world of Linux. Here some tips:
- You can use the clear command to clear the terminal
- Enter TAB can be used to fill the rest of the text of the command. For example after you type cd doc and press TAB it will automatically fill it as cd documents
- you can close the terminal by typing in exit
- You can turn the computer ON and reboot the computer by using the sudo halt and sudo reboot
If you liked this article let us know in the comments below and if we are missing some basic commands let us know.