Basic Linux Commands You Need To Know: Best In 2020

Basic Linux Commands

Basic Linux Commands

When you hear about Linux, most people immediately refer to a complex operating system used only by programmers. Even though Linux is not as scary as one thought so far.

Linux is a family of open-source Unix operating systems and is based on the Linux Kernel. This ‘family’ also includes popular Linux-based systems such as Ubuntu, Fedora, Mint, Debian, and others. These systems are more accurately referred to as distributions or distros.

Since it was first released in 1991, Linux has skyrocketed in popularity due to its open-source nature. Users are free to modify Linux and distribute it under their own name.

When operating a Linux OS, you must use a shell, an interface that provides access to operating system services. Most Linux distributions use a graphical user interface (GUI) as their shell, primarily to provide ease of use for users.

Thus, the use of the command-line interface (CLI) is highly recommended because it is more powerful and effective. Tasks that require a multi-step process via the GUI can be performed in seconds by typing commands into the CLI.

So, if you want to use Linux, you must know the basic Linux commands. In this article, you will learn the 35 most basic Linux commands that will help you as a newbie to explore Linux.

Read More: Different Parts of Pc or Computer and Working Methods 

Basic Linux Commands

Before describing the basic commands of the Linux operating system, you must open the command line first. If you haven’t used a command-line interface before.

Although the steps to follow differ depending on the distribution used, the command line is usually located in the Utilities section.

Here’s a list of basic Linux commands:

1. pwd command

The basic command for Linux pwd is to find the path of the directory (folder) you are currently using. This command will return an absolute (full) path, which is basically the path of all directories beginning with a forward slash (/). An example of an absolute path is / home/username.

2. cd command

To browse Linux files and directories, use the cd command. This Linux command requires the full path or directory name, depending on the directory you are currently using.

Suppose you are currently in / home/username / Documents and want to open Photos, a subdirectory of Documents. To do so, you just need to type this command: cd Photos.

Another example, when you want to switch to a completely new directory, for example, / home/username / Movies. In this example, type cd followed by the absolute directory path: cd / home / username / Movies .

Here are some shortcuts (shortcut) for easy navigation:

  • cd .. (with two periods) to move one directory up.
  • cd if you want to directly open the home folder.
  • cd- (with a hyphen) to move to the previous directory.

One thing to note, the Linux shell is very sensitive. So, you have to type the directory name correctly and precisely.

3. Is command

Is a basic command in Linux that is used to view the contents of a directory. By default, this command will display the contents of the directory you are currently using.

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

Here are some variations that can be combined with the basic Linux Is command :

  • Is -R will list all the files in the sub-directory.
  • Is -a will show hidden files.
  • Is -al will list files and directories containing detailed information, such as permissions, size, owner, etc.

4. cat command

cat (acronym dri concatenate ) is one of the most commonly used commands of the Linux operating system. This command is used to list the contents or file contents in standard output (sdout). To run this command, type cat followed by the file name and extension. For example cat file.txt.

There are several ways to use the cat command :

  • cat> filename to create a new file.
  • cat filename1 filename2> filename3 to merge two files (1 and 2) and save the output in a new file (3).
  • filename paint | tr az AZ> output.txt to convert the file to uppercase or lowercase letters.

5. cp command

Use the basic Linux cp command to copy files from the current directory to a different directory. For example, the command cp scenery.jpg / home/username / Pictures creates a copy of scenery.jpg (from the current directory) to the Pictures directory.

6. mv command

The main function of the mv command is to move files even though it can actually be used to rename or rename files.

The arguments in mv are similar to those in the cp command. Type mv, file name, and destination directory. Example: mv file.txt / home / username / Documents .

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

7. mkdir command

To create a new directory, you can use the basic Linux mkdir command. For example, if you type mkdir Music, the new directory that appears is called Music.

Here are some additional mkdir commands :

  • To create a new directory inside another directory, use the basic Linux command mkdir Music / Newfile .
  • Use the (parents) option to create a directory between two existing directories. For example, mkdir -p Music / 2020 / Newfile to create a new file “2020”.

8. rmdir command

If you want to delete a directory, use the rmdir command. However, rmdir should only be used to delete empty directories.

9. rm command

rm is a basic command in Linux that functions to delete a directory and its contents. If you only want to delete the directory – an alternative command to rmdir – use rm -r.

Note: When using this command, you have to be careful and double-check the directory you are currently in. Once the rm command is executed, everything will be deleted and cannot be recovered.

10. touch command

touch is a basic Linux command that lets you create new, blank files via the Linux command line. For example, type touch /home/username/Documents/Web.html to create an HTML file titled Web under the Documents directory.

11. locate command

locate is used to find files, has the same function as the search command in Windows OS. When paired with the -i argument, this command is case-insensitive so files can be searched even if you don’t remember their name correctly.

To search for files containing two or more words, use an asterisk (*). For example, the command locate -i school * note will search for files whose names contain the words “school” and “note”, whether they are uppercase or lowercase.

12. find command

Just like the locate command, the find command can also be used to search for files and directories. The difference is, the find command is more intended to search for files located in a given directory.

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

Here are a few variations that can be paired with find :

  • find. – name notes.txt to find files in the current directory.
  • / -type d -name notes.txt to find a directory.

13. grep command

Another basic Linux command that comes in handy for completing daily tasks is grep. With this command, you can perform a search across all text in the given file.

For example, type grep blue notepad.txt to look up the word blue in the notepad file. Lines containing the search term are fully displayed.

14. sudo command

sudo stands for “SuperUser Do ” and functions to perform tasks that require administrative or root permissions. However, we don’t recommend using the sudo command for daily tasks because it can get an error at any time if you make a mistake.

15. df command

To get a report on system disk space usage, use the df command. Reports given are present in percentage and KB units. If you want to see the report in megabytes, type df -m .

16. du command

du is a basic Linux command that checks how much space is used by a file or directory. However, for the summary format, the disk usage is displayed as the disk block number instead of the usual size format. If you want to see the total disk usage in bytes, kilobytes, and megabytes, add the -h argument to the command line.

17. head command

The head command is used to view the first line of all text files. By default, this command will display the first ten lines. However, the number of lines can be changed according to your wishes. For example, if you wanted to display only the first five lines, type head -n 5 filename.ext

18. tail command

The tail command has the same function as the head command. It’s just that, instead of the first line, the tail command will display the last ten lines of a file. For example, tail -n filename.ext.

19. diff command

diff is a basic Linux command that compares the contents of two files on a line by line basis. After analyzing the file, this command will output a line or lines that do not match. Programmers often use this command when they need to make program changes, instead of rewriting all the source code.

The simplest format of this basic Linux command is diff file1.ext file2.ext .

20. tar command

tar is the most widely used Linux command for archiving multiple files into a tarball – a Linux file format similar to the zip format, where the compression action is optional.

The basic commands for this Linux operating system are quite complex with a long list of functions, such as adding new files to an existing archive, listing the contents of an archive, extracting content from an archive, and much more. To know more about the other functions, please check out simple examples here.

21. chmod command

chmod is another basic Linux command that is used to read, write, and enforce file and directory permissions. Because this command is quite difficult, so to run it, please read this complete tutorial first.

22. chown command

On the Linux operating system, all files are owned by a special user. As a basic Linux command, chown allows you to change or transfer ownership of files to a custom or specific username. For example, chown linuxuser2 file.ext will specify linuxuser2 as the owner of the file.ext .

23. jobs command

The jobs command will display all current jobs along with their status. Basically, a job is a process that is started by the shell.

24. kill command

If none of the programs are responsive, you can kill them manually using the basic Linux kill command. This command will send a specific signal to the problematic application and give instructions to the application to end or shut down by itself.

In total there are 64 signals that can be used, but usually, people only use two signals, namely:

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

In addition to signals, you also need to know the process identification number (PID) of a program that you are trying to kill. If you don’t know the PID, you can run the ps ux command.

After knowing the signal you want to use and the program PID, enter this syntax: kill [signal option] PID.

25. ping command

The ping command is used to check the connectivity status to the server. For example, by adding ping google.com, the command will check whether you are connected to Google or not and also measure the response time.

26. wget command

These basic Linux commands are very useful – you can even download files from the internet with the help of the wget command. You just need to type wget followed by the download link.

27. uname command

uname, an acronym for Unix Name, is a basic command for the Linux operating system that prints complete information about the Linux system, such as machine name, operating system, kernel, and so on.

28. top command

As a terminal equivalent to the Task Manager in Windows, the command top will display a list of processes in progress and how much CPU space each process is taking up. Monitoring system resource usage is highly recommended, especially when you have to figure out which processes need to be killed because they are using too many resources.

29. history command

If you are good at using Linux, you can run hundreds of commands or commands every day. For example, using the command history to check back ( review ) the commands that have been added previously.

30. mand command

Confused by the function of certain Linux commands? To learn this straight from the Linux shell, you can use the command man. For example, by adding the man tail commandyou will be presented with the instruction manual of the tail command.

31. echo command

This basic Linux command is used to move multiple data into one file. For example, if you want to add the text, “Hello, my name is John” to a file called name.txt, you would type echo Hello, my name is John >> name.txt.

32. zip, unzip command

Use the zip command to compress files to a zip archive and the unzip command to extract the zip file to a zip archive.

33. hostname command

hostname is a basic Linux command that you can use if you want to know the host / network name. By adding -I to the end of the command, the network IP address will be displayed.

34. useradd, userdel command

Linux is a multi-user system, and this means that there are many people who can interact on the same system at the same time. useradd is a basic Linux command that is used to create a new user, while passwd is to add a password to that user’s account. To add a user named John, for example, simply type useradd John and passwd 12345678 to add the password.

How to delete a user is the same as adding a user. To delete a user account, type userdel UserName .

Bonus: Tips and Tricks

Use the clear command to clean the terminal if it contains a lot of commands.

Try the TAB key to autofill what you are typing. For example, if you want to type Documents, start by adding the command first (eg cd Docu, then press the TAB key ) and the terminal will complete it. The result will be like this: cd Documents.

Ctrl + C and Ctrl + Z are used to interrupt any commands that are currently running. Ctrl + C will stop the command safely, while CTRL + Z will force the command to stop.

If you inadvertently ‘freeze’ the terminal by pressing Ctrl + S, to cancel the ‘freezing’ is just press Ctrl + Z.

Ctrl + A takes you to the beginning of the line, while Ctrl + E takes you to the end of the line.

You can run multiple commands or commands in one command using ““To separate these commands. For example, Command1; Command2; Command3 . Or use && if you just want to run the next command after the first command has been successfully executed.

Conclusion

Linux basic commands help users or users to perform tasks easily and effectively. It’s not easy to remember all the Linux commands above. However, everything will be resolved if you keep practicing and practicing.

LEAVE A REPLY

Please enter your comment!
Please enter your name here