Basic Linux Commands You Must Know

Basic Linux Commands

The following are some basic Linux commands that are widely used:

1. pwd

When you first open the terminal, you will enter your user's home directory. To know which directory you are currently in, you can use this "pwd" command.

With this command, they will tell you the path starting from root. Root is the prefix of the Linux file system. The user directory usually has a format like "/home/username".

2. Is

The "Is" (Ls) command in Linux is used to find out what files are in the directory you are currently open. You can see hidden files by using the "Is-a" command.

3. cd

Use the "cd" command to enter a directory. For example, if you are in the home folder and you want to enter the downloads folder, you can enter the command "cd Downloads". This command is case sensitive so you need to enter the folder name correctly.

Also, if your folder has two or more names, you need to insert a \ sign between the folder names.

For example, you have a folder named "Web God". If you enter the command "cd Dewa Web", you will get an error message. So, you need to enter the command as "cd Dewa\Web". If you just enter "cd" you will be taken to the home directory.

To go back to the previous folder, just enter "cd..". The colon after cd means "back".

4. cat

The cat command (acronym for concatenate) serves to list the contents or contents of a file on standard output (sdout). To run this command, type cat followed by the file name and extension. For example: cat file.txt.

5. mkdir

Use the mkdir command when you need to create a folder or directory. For example, if you want to create a directory with the name "New", then you just need to enter the command "mkdir Baru". If you want to create a directory with more than one word in the name, just like in the previous command, you need to use the \ sign. So, you should type "mkdir Folder\New".

6. rmdir

The rmdir command is used to delete a directory. But this command can only be used to delete empty directories. If you want to delete a directory that still contains files, use the "rm" command which will be discussed below.

7. rm

The rm command is a Linux command used to delete directories and files. So for example you want to delete a file called "lama.html", you just enter the command "rm lama.html". But this basic command can't just delete directories. Use rm-r to delete the directory. This will delete the directory and its contents.

8. touch

touch is used to create a new file. This can be anything from an empty txt file or an empty zip file. For example, if you want to create a new text file, you can just enter "touch new.txt".


9. man & –help

These two commands are used to know more about Linux commands and how to use them. The "man" command is the command manual page. For example, if you enter "man rm" then they will give you the rm command manual page. Meanwhile, if you want to see how they are used, you can use the "cd -help" command.

10. cp

The cp command in Linux is used to copy files from the current directory to another directory. For example, when copying from sample.txt to the Documents directory.

11. mv

mv is used to move files. You can also use this basic command to rename a file. For example, you want to rename a file from "new" to "old". Then you just enter the command "mv new old".

12. locate

This one command is used to find the location of a file in Linux systems, just like the search command in Windows.

Locate is very useful if you can't find where a file is stored. If you don't know whether a file is capitalized or lowercase, you can add the command "-i" to get all files containing that word out.

For example, if you are looking for a fle that contains the word "domain" you can enter the command "locate -i domain". If you remember that the file contains two words, you can use the * symbol between the two words. For example, if you want to find a file that contains the word "your domain", just enter "locate -i *domain*you".

13. nano & vi

Nano is a text editor that can output various keywords and is recognized in various languages. Vi is arguably simpler than nano. With this command, you can create new files or edit files using the editor.

14. sudo

sudo is a commonly used command on Linux. Sudo comes from "SuperUserDo". This command can be used if an operation requires root privileges to be used, or if administrative access is required.

For example, by using the "sudo su" command, we can start processing with admin authority on the system.

15. Find

Similar to the locate command, the find command is also used to search for files and directories. The difference is that the find command is more intended to find files located in the given directory.

16. Head

Command head is used to view the first line of all text files. This command will display the first 10 lines but you can customize it. For example, if you want to display the first 3 lines, then just type head -n 3 filename.ext.


17. Tail

If the head command displays the first few lines, the tail command displays the last few lines only. For example, tail -n filename.ext.

18. Diff

The diff command functions to compare the content or contents of two files on a line-by-line basis. After analyzing the files, this command will produce output in the form of lines or lines that do not match. This command is often used when programmers need to make program changes so they don't have to rewrite all the source code from scratch.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.