What is Linux?
Linux is one of the popular operating systems on the planet. It is the entire family of open-source Unix operating systems based on Linux kernel, which includes Ubuntu, Mint, Debian, and other distros.
Linux was first released by 1991 by Linus Torvalds. Because it is open-source, people can freely modify it and redistribute it under their own name.
What is the Terminal?
While working with a Linux OS, you need to use a shell (a command-line interface that helps you control the operating system’s services). Command Line Interface is powerful and effective; the multi-step process taken through GUI is easily done in seconds.
While working with Linux terminal, learning basic Linux commands will surely help you navigate through the system. In this article, we will cover the basic commands that we use in the Linux shell.
How to open a Terminal?
You can open Terminal on a Linux System by directly pressing Ctrl+Alt+T, or you can search it up by clicking the “Dash” icon, typing in “terminal” in the search box.
Basic Linux Commands
1. pwd
If you want to find out the absolute directory path you are currently in, you can do so using the pwd command. Absolute directory looks like “/home/user/”. It starts with a forward slash “/” which is the root Linux file system.
2. ls
If you want to list or view a directory’s contents, you can do so by using the ls command.
To view the contents of the directory, you are in type ls in the Terminal. If you want to see the contents of any other directory enter ls and full pathname of the directory. For example, ls /home/user/Downloads/ will list the contents of the Downloads folder.
You can view the hidden files by typing ls -a. You can list the files in the sub-directories by typing ls -R. You can list the files and directories with detailed information by typing ls -al
3. cd
The cd command is used to change the directory, or navigate through them. Using cd command requires the directory path or the name (if it’s in the current directory)
Suppose, you are in /home/user/Downloads and you want to go to /home/user/Documents/Files then type the directory’s absolute path cd /home/user/Documents/Files.
Linux’s shell is case sensitive so, you have to type the exact name of the directory.
cd will move you straight to home folder
cd .. (two dots) will move you one directory up
cd – (hyphen) will transfer you to your previous directory
4. mkdir
The mkdir command helps you create a new directory (folder).
mkdir Rudrax will create a new directory called “Rudrax”.
To generate a new directory inside another directory, you can write mkdir Rudrax/Files.
5. rmdir
If you want to delete a directory, you can use the rmdir command to do so. But, it only can be used to remove an empty directory.
6. touch
If you want to create a new blank file, you can use the touch command. For example, touch hello-world.txt will create a new text file called “hello-world.txt”.
7. rm
You can delete the directories and the contents within them using the rm command. By default, the rm command does not remove directories. If you want to remove the directory, use the rm -r command.
8. mv
The primary use of the mv command is to move files, but it also can be used to rename files. The arguments used in mv command are similar to the cp command. You can use it like mv hi.txt /home/rudrax/Documents/Files.
You can also rename the files by using mv hello.txt hi.txt
9. man
The man function shows the manual for the command you type. Typing man touch will show the manual instructions for touch command.
10. history
This command will show you the commands you have entered before.
11. diff
This command compares the content of two files line by line. After analyzing it displays the lines which do not match. You can use it by typing diff file1 file2
12. cp
The cp command helps to copy files from the current directory to a different directory. For example, cp hello.txt /home/rudrax/Documents will create a copy of hello.txt into the Documents folder.
13. cat (short for concatenate)
You can use this command to list the content of a file on standard output. To use this command type cat and name of the file with its extension. For instance: cat hi.txt
cat > file creates a new file (you can write any text and save using ctrl + D)
cat file1 file2 > file3 joins file1 and file 2 to create a new file3
14. locate
You can use this command to search for a file. Use the argument -i to make it case-insensitive so that you don’t have to search for the exact name.
How to use: Use * to search for the file which contains two or more words. For example, locate -i god*war will search for any file that contains the word “god” and “war”.
15. find
If you want to search for files within the given directory you can use find command. It’s just like the locate command, but it will search in a given directory.
For example, find /home/ -name hello.txt will search for hello.txt file in the home directory and its subdirectories.
16. sudo
It is a widely used command to provide the administrative or root access to perform a certain task. It stands for “SuperUser Do.”
17. df
Use this command to view available disk space in each partition of your system. If you want to show it in megabytes, just type df -m.
18. du
You can use this command to view the disk usage of a file in your system.
19. tar
You can use this command to work with compressed tarball archives. It can be used to compress and uncompress different types of tar archives.
20. chmod
The chmod command helps to change the read, write, and execute permissions of the file and directories.
21. chown
The chown command helps to transfer or change the ownership of files to a different user in the Linux system.
22. wget
You can download files from the internet using this simple wget command. just type wget followed by the link of the file you want to download.
23. ping
ping command helps you to check the connectivity status to a server. You can measure the response time to connect to a certain server. Typing ping facebook.com will show the response time taken to connect to the Facebook server.
23. kill
kill is a useful command to terminate a program if it becomes unresponsive. It will send a response to the unresponsive app to terminate itself.
24. zip and unzip
You can use the zip command to compress the files into a zip archive and unzip command to extract the files from the zip archive.
25. uname
uname command will show you the information about the Linux distro you are using. Use uname -a to print the most information about the system.
26. apt-get
You can use the apt-get command to install packages. It requires root privileges, so you have to use it with the sudo command. sudo apt-get vlc will install VLC media player in your system.
It is a good idea to update your repository each time you try to install a new package by typing sudo apt-get update.
27. Bonus Techniques
You can use clear command to clear out the Terminal screen if the screen is filled with too many commands.
You can use Tab key on your keyboard to autofill the typing.
Use Ctrl + C to stop and terminate any command which is currently running. Use Ctrl + Z to pause the command simply.
Use multiple commands using Semicolon “;”
These are the useful basic Linux commands. Use them well, and you will be familiar with the Linux system. If you are comfortable with these commands, you can learn more Intermediate Linux commands.
Thank you and Stay Safe!