30 Linux Commands Every User Should Know

30 Linux Commands Every User Should Know

When you hear Linux[1], most people think of a complex operating system that only programmers use. However, this is not the case; although Linux may seem daunting to ordinary users and requires many command operations to use, in reality, you can operate it smoothly with just a few commands.

In this article, you will learn 30 basic commands that will undoubtedly help you familiarize yourself with Linux as a beginner.

What is Linux?

Linux is an entire family of open-source Unix operating systems based on the Linux kernel. This includes all the most popular Linux-based systems such as Ubuntu[2], Fedora[3], Mint[4], Debian[5], etc. More accurately, they are collectively referred to as Linux distributions.

Although Linux has a much smaller market share on desktop computers compared to Windows and MacOS, it is extremely popular in server systems provided by virtual hosting providers. Due to the stability, flexibility, and security of Linux systems, 36.7% of all websites use Linux as their server operating system.

Running Linux

Most Linux distributions provide a graphical user interface (GUI) primarily to make it easier for users. However, in reality, typing some commands in the CLI (command line interface) can accomplish tasks that would require multiple steps through the GUI in just a few seconds.

Therefore, if you are considering using Linux, learning the basic command line commands will be very helpful.

Are you ready? Now let’s explore these 30 basic commands in Linux.

1. pwd Command

The pwd command can be used to find the path of your current directory (folder). This command will return the absolute (full) path, which essentially starts with a forward slash (/). An example of an absolute path is /home/username.

2. cd Command

To navigate the Linux file system, you can use the cd command. It requires either the full path or the directory name, depending on your current directory.

Assuming you are in /home/username/Documents and want to go to the subdirectory Photos, you would simply type cd Photos.

Another scenario is if you want to switch to a completely new directory, such as /home/username/Movies. In this case, you must type cd followed by the absolute path of the directory.

If you want to navigate quickly, you can use some shortcuts. Using cd .. (with two dots) will move up one directory, or use cd to go directly to the home folder. To move to the previous directory, type cd – (with a hyphen).

Note that Linux is case-sensitive in the command line. Therefore, you must enter the directory names exactly.

3. ls Command

The ls command is used to view the contents of a directory. By default, this command will display the contents of the current directory.

If you want to view the contents of another directory, type ls followed by the path of the directory. For example, type ls /home/username/Documents to see the files in that directory.

4. cat Command

cat command is one of the most commonly used commands in Linux. It is used to view the contents of a file on standard output (stdout). To run this command, type cat followed by the filename and its extension. For example: cat file.txt.

5. cp Command

Use the cp command to copy files from the current directory. For example, the command cp scenery.jpg /home/username/Pictures will create a copy of scenery.jpg in the Pictures directory.

6. mv Command

mv command is primarily used to move files, although it can also be used to rename files.

The parameters for this command are similar to those of the cp command. You need to enter mv, the filename, and the target directory. For example: mv file.txt /home/username/Documents.

To rename a file, the syntax is mv oldname.ext newname.ext

7. mkdir Command

Use the mkdir command to create a new directory. For example, mkdir Music will create a new directory named Music.

8. rmdir Command

If you need to delete a directory, use the rmdir command. However, rmdir only allows you to delete empty directories.

9. rm Command

The rm command is used to delete directories along with their contents. If you only want to delete a directory (as an alternative to rmdir), use rm -r.

10. touch Command

The touch command can create a new blank file via the command line. For example, typing touch /home/username/Documents/Web.html will create an HTML file named Web in the Documents directory.

11. locate Command

You can use this command to locate files, similar to the search command in Windows. Additionally, using the -i parameter with this command will make it case-insensitive, allowing you to search for files even if you do not remember their exact names.

To search for files containing two or more words, use an asterisk (*). For example, the command locate -i school*note will search for any files containing the words “school” and “note”, regardless of case.

12. find Command

Similar to the find command, using find can also search for files. The difference is that you can use the find command to locate files within a given directory.

For example, the command find /home/ -name notes.txt will search for a file named notes.txt in the home directory and its subdirectories.

13. grep Command

The grep command is another very useful command for everyday use.grep allows you to search for all text within a given file.

For example, grep blue notepad.txt will search for the word “blue” in the notepad file. The lines containing the searched word will be displayed in full.

14. sudo Command

This command is short for “SuperUser Do“, allowing you to perform tasks that require administrative or super user permissions. However, it is advised not to use this command for everyday tasks, as it is easy to make irreversible mistakes if you are not careful.

15. df Command

Use the df command to get a report on the system’s disk space usage, expressed in percentage and KB. If you want to view the report in megabytes, type df -m.

16. du Command

If you want to check how much space a file or directory occupies, you can use the du (disk usage) command. However, the disk usage summary will display the number of disk blocks rather than the usual size format. If you want to view it in bytes, kilobytes, and megabytes, add the -h parameter in the command line.

17. head Command

The head command is used to view the first lines of any text file. By default, it will display the first ten lines, but you can change this number according to your preference. For example, if you only want to display the first five lines, type head -n 5 filename.ext.

18. tail Command

This command has a similar function to the head command, but the tail command will display the last ten lines of a text file instead of the first lines.

19. diff Command

diff command is short for differences, and the diff command compares the contents of two files line by line. After analyzing the files, it will output the lines that do not match. This command is often used by programmers when they need to make some changes to a program rather than rewriting the entire source code.

The simplest form of this command is diff file1.ext file2.ext

20. tar Command

The tar command is one of the most widely used commands to archive multiple files into a compressed package, which is a common Linux file compression format.

This command is quite complex and has many functions, such as adding new files to an existing archive, listing the contents of an archive, extracting content from an archive, and more. Check out some real examples,[6] to learn more about other features.

21. chmod Command

chmod is another basic command used to change the read, write, and execute permissions of files and directories. Since this command is quite complex, you can learn how to use it specifically by typing <span><span>man chmod</span></span> in the command line.

22. chown Command

In Linux, all files belong to a specific user. The <span><span>chown</span></span> command allows you to change the ownership of a file to a specified username. For example, chown linuxuser2 file.ext will make linuxuser2 the owner of file.ext.

23. jobs Command

jobs command will display all current jobs and their status. Jobs are essentially processes started by the Shell.

24. kill Command

If your program is unresponsive, you can use the kill command to manually terminate it. It will send a specific signal to the malfunctioning application, instructing it to terminate itself.

A total of sixty-four signals can be used, but people usually only use two signals:

SIGTERM (15) – requests the program to stop running and gives it some time to save all its progress. If no signal is specified when entering the kill command, this signal will be used.SIGKILL (9) – forces the program to stop immediately. Unsaved progress will be lost.

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 do not know the PID, simply run the command ps ux.

Once you know the signal you want to use and the PID of the program, enter the following syntax:

kill [signal option] PID.

25. ping Command

Use the ping command to check the connection status with a server. For example, simply type ping baidu.com, and this command will check if you can connect to Baidu and measure the response time.

26. wget Command

The wget command is very useful; you can use it to download files from the Internet. To do this, simply type wget followed by the download link. You can check this to learn more about wget usage[7].

27. uname Command

The uname command can print detailed information about your Linux system, such as the computer name, operating system, kernel, etc. Type man uname in the command line to learn more about its parameters.

28. top Command

As the terminal equivalent of the task manager in Windows, the top command will display a list of running processes and how much CPU each process is using. It is very useful for monitoring system resource usage, especially when you need to know which process is consuming too many resources and needs to be terminated.

29. history Command

After using Linux for a while, you will quickly notice that you can run hundreds of commands daily. Therefore, running the history command is particularly useful if you want to see the commands you entered previously.

30. man Command

If you are confused about the functionality of certain commands, don’t worry; you can easily learn how to use them from the Linux shell using the man command. For example, typing man tail will display detailed instructions on how to use the tail command.

In Conclusion

Linux commands can help users perform tasks easily and efficiently. Remembering some basic commands may take some time, but with plenty of practice, nothing is impossible to learn.

Finally, understanding and mastering the commands above will undoubtedly be beneficial to you!

References

<span>[1]</span> Linux: https://linux265.com/distro/<span>[2]</span> Ubuntu: https://linux265.com/distro/45.html<span>[3]</span> Fedora: https://linux265.com/distro/15.html<span>[4]</span> Mint: https://linux265.com/distro/23.html<span>[5]</span> Debian: https://linux265.com/distro/10.html<span>[6]</span> Examples: https://linux265.com/news/3953.html<span>[7]</span> wget usage: https://linux265.com/news/2174.html

30 Linux Commands Every User Should KnowScreenshot methods in LinuxScreenshot tools in Linux – FlameshotHomebrew is also good in Linux!Aurora, another immutable Linux distribution!Recommended 3 minimal Linux distributionsWhy learn the Linux system?Old friend, remember to 🌟star so it’s easier to find me next time!

Leave a Comment