Introducing 33 basic Linux commands
It is better to know basic Linux commands if you are a Linux user or have a Linux virtual server. Because it will come in handy, in this post, we will first briefly introduce Linux and then introduce Linux commands.
Hearing the name Linux, most people think of a complex and difficult operating system that programmers only use. But it is not as difficult as it seems.
Linux is a family of open-source Unix operating systems based on the Linux kernel. The most popular Linux-based systems include Ubuntu, Fedora, Mint, Debian, and cents. Which is strictly called a distribution.
Since it was first released in 1991, Linux has remained popular due to its open-source nature.
When working with the Linux operating system, you need to use the Shell – an interface that allows you to access the operating system’s services. Most Linux distributions use a graphical user interface (GUI) as their Shell, mainly to provide ease of use for their users. Using them is very useful for VPS management.
Using a command line interface (CLI) is recommended because it is more powerful and effective. Tasks that require a multi-step process through the GUI can be done in seconds by typing commands into the CLI.
Basic Linux commands
First, open the command prompt. Although the steps may vary depending on the distribution you’re using; you can usually find the command line in the utility section.
1. pwd
The pwd command is used to find the path of the current directory (or folder) you are in. This command returns a full path, which is a path of all directories. And starts with a forward slash (/). For example: home/username/
2. cd
To navigate through Linux files and directories, use the cd command. It requires the full path or directory name, depending on your current directory.
Let’s say you’re at /home/username/Documents, and you want to go to Photos, a subfolder of Documents. To do this, type the following command: cd Photos.
Another scenario is you want to go to a completely new path, for example, /home/username/Movies. In this case, you should type cd followed by the full directory path: cd /home/username/Movies.
Some shortcuts for faster navigation:
- cd ..: (after cd I put two dots) to go to the next directory
- cd : to go directly to the root folder
- -cd : to move to the previous directory
[highlight color=” yellow”]Important note: Linux is Case Sensitive and is sensitive to uppercase and lowercase letters.[/highlight]
ls.3
The ls command is used to view the contents of a directory. By default, this command displays the contents of your current directory.
But if you want to see the contents of other directories, just type ls first and then the directory path. For example, type ls /home/username/Documents to view the contents of Documents.
ls shortcuts
- ls -R: Lists all the files in the subdirectories.
- ls -a : Show hidden files.
4. Cat
cat (short for Concatenate) is one of the most used commands in Linux. Used to list the contents of a file to standard output (sdout). To execute this command, type cat and then the file name and its extension. For example cat file.txt
Other methods of using the cat command:
- cat > filename: Create a new file
- cat filename1 filename2>filename3: joins two files (1 and 2) and saves their output in a new file (3).
- To convert a file to uppercase or lowercase letters: cat filename | tr a-z A-Z >output.txt
5. cp
Use the cp command to copy files from the current directory to another directory. For example, the command cp scenery.jpg /home/username/Pictures creates a copy of scenery.jpg (from your current directory) in the Pictures directory.
6. mw
The main use of the mv command is to move files, although it can also be used to rename files.
The arguments in mv are the same as in the cp command. It would help if you typed mv, filename, and destination directory. For example: mv file.txt /home/username/Documents
You can also use the mv oldname.ext newname.ext command to rename the files.
7. mkdir
Use the mkdir command to create a new directory. For example, if you type mkdir Ded9com, a directory called Ded9com will be created.
Additional mkdir commands:
To create a new directory inside another directory, use the Linux mkdir Music/Newfile command.
Use the p (parents) option to create a directory between two existing directories. For example, the command mkdir -p Music/2020/Newfile creates the new file “2020”.
8. rmdir
If you need to remove a directory, use the rmdir command. However, rmdir only allows you to remove empty directories.
9. rm
The rm command is used to delete directories and their contents. If you just want to remove a directory, you can use rm -r as an alternative to rmdir.
Note: Be very careful when using this command and double check which directory you are in. By doing this, everything is erased and there is no possibility of undoing.
10. touch
The touch command allows you to create a new empty file from the Linux command line. For example, run touch /home/username/Documents/Web.html to create an HTML file titled Web in the Documents directory.
11. find
You can use this command to locate a file, just like the search command in Windows. Using the -i argument with this command makes it case-sensitive, so you can search for a file even if you don’t remember its exact name.
For example, the command find /home/ -name notes.txt searches for a file named notes.txt in the home directory and its subdirectories.
- To find files in the current directory: find . -name notes.txt
- To search directories: / -type d -name notes. txt
12. grep
Another basic Linux command that is undoubtedly useful for everyday use is grep. Allows you to search the entire text of a specified file.
For example, the grep blue notepad.txt command searches for the word blue in the notepad file. Lines that contain the searched word are displayed in their entirety.
13. sudo
This command stands for “SuperUser Do” which allows you to do things that require root permissions.
14. df
We use the df command to get a report of the system disk space usage shown as a percentage and in kilobytes. If you want to see the report in megabytes, type df -m.
15. du
If you want to check how much space a file or directory is taking up, use the du (disk usage) command. However, the disk usage summary shows disk block numbers instead of the usual size format. If you want to see it in bytes, kilobytes, and megabytes, add the -h argument to the command line.
16. head
The head command views the first lines of any text file. By default, it shows the first ten lines, but you can change this number to your liking. For example, if you want to show only the first five lines, type head -n 5 filename.ext.
17. tail
This one has the same function as the head command, but instead of displaying the first lines, the tail command displays the last ten lines of a text file. For example, tail -n filename.ext.
18. diff
The diff command compares the contents of two files line by line. After parsing the files, it outputs the lines that do not match. Programmers often use this command when they need to make changes to the program instead of rewriting the entire source code.
The simplest form of this command is diff file1.ext file2.ext.
19. tar
The tar command is the most widely used command to archive multiple files in a tarball. (a common Linux file format that is similar to the zip format and compression is optional.)
This command can be used with a long list of functions, such as adding new files to an existing archive, listing archive content, extracting content from an archive, and many more.
20. chmod
chmod is another Linux command used to change the read, write and execute permissions of files and directories.
21. Chown
In Linux, all files belong to a specific user. The chown command enables you to change or transfer ownership of a file to the specified username. For example, chown linuxuser2 file.ext makes linuxuser2 the owner of file.ext.
22. jobs
The jobs command displays all current jobs along with their status. A job is a process started by the Shell.
23. kill
If you have a program that is not responding (so-called “hanging”), you can disable it manually using the kill command. This command instructs the program to terminate its work.
There are a total of 64 signals that you can use. But mostly only these two signals are used:
- SIGTERM (15): Requests a program to stop execution and gives it some time to save all its progress. If you do not specify a signal when entering the kill command, this signal will be used.
- SIGKILL (9): Stop the program immediately.
In addition to knowing the signals, you also need to know the process identification number (PID) of the program you want to kill. If you don’t know the PID, simply run the ps ux command.
Once you know the signal you want to use and the PID of the program, enter the following command:
kill [signal option] PID
24. Ping
Use the ping command to check the status of your connection to the server. For example, by ping google.com, this command checks if you can connect to Google and measures the response time.
25. wget
The Linux command line is very useful. You can download files from the Internet with the help of the wget command. For this, just type wget and then type the download link.
26. uname
The uname command, which stands for Unix Name, prints detailed information about your Linux system, such as machine name, operating system, kernel, etc.
27. top
Like Task Manager in Windows, the top command displays a list of running processes and their CPU usage. Monitoring system resource usage is very useful, especially knowing which process should be terminated as it may be consuming too many resources.
28. history
After using Linux for a while, you will realize how various Linux commands are. You can use the history command when you want to see the history of entered commands.
29. Man
Using the man command, you can easily learn how to use Linux commands directly from the Linux shell. For example, entering the man tail displays the manual command tail command.
30. echo
This command is used to transfer some data to a file. For example, if you want to add the text “Hello, my name is John” to a file named name.txt, you would type echo Hello, my name is John >> name.txt.
31. zip, unzip
Use the zip command to compress your files into a zip archive. Use the unzip command to extract compressed files from a compressed archive.
32. hostname
If you want to know your host/network name, simply type hostname. Adding an -i to the end will display your network’s IP address.
33. useradd, userdel
Since Linux is a multi-user system, it means that more than one person can interact with the same system at the same time. useradd is used to create a new user, while passwd adds a password to that user’s account. To add a new person named John, type useradd John, and then enter passwd 123456789 to add your password type.
conclusion
Basic Linux commands help users to get things done easily and efficiently. It may take some time to remember some of the basic commands, but nothing is impossible with a lot of practice.
If you want an affordable Linux virtual server, don’t miss Ded9.com’s offers.