Get In Touch
hello@gmail.com
Wa: +92-300-076-24-60
Back

25+ Basic Linux Commands [Complete with Functions & Examples]

25+ Basic Linux Commands [Complete with Functions & Examples]

Some people may think that Linux is an operating system that is difficult to operate because it has to deal with a complex command line. This of course, is not entirely true. If you can understand basic Linux commands, you also have the opportunity to master the command line like a reliable system administrator.

This article will review some basic Linux commands, along with explanations of their functions and examples.

{jistoc} $title={Table of Contents}

List of Basic Linux Commands and Their Functions

To be able to operate Linux, you need to access the shell, which is a text-based interface for writing commands and instructing the computer to perform certain tasks.

This shell or terminal is usually found in the utility menu on the device. However, you can also access it by pressing Ctrl+Alt+T.  

After successfully opening the shell/terminal, let's immediately find out some of the most frequently used basic Linux commands!

Keep in mind, all commands must be written in lowercase. 

1. pwd 

When you want to create, view, or delete files, you need to make sure you're in the right directory, right?

Well, pwd or print working directory will provide information about the active directory you are currently accessing. The result of the command is something like /home/username.    

2. cd

If the directory you are accessing at that time is not correct, you can use the cd (change directory) command to change or open a specific directory.

For example, you are in the Home directory and want to access the Downloads folder. Well, you just need to write the command cd Downloads

3. mkdir

The mkdir (make directory) command is used to create a new folder or directory. To add to the Movies directory, for example, you could write mkdir Movies.

In addition, you can also create directories in other existing directories. To do this, type the name of the old directory followed by the new directory, such as mkdir Movies/Actions.    

4. rmdir

If you want to delete a directory, you can use the rmdir command. But please note, this command can only delete directories that are still empty.

Alternatively, you could also write rm -r to get the same functionality as rmdir.  

But keep in mind, you need to be careful using rm -r. Make sure you have written the folder/file name after the rm -r command (example: rm -r Movies/Actions).

If you forget to include the name of the folder/file, then what happens is that you will delete the entire directory on the server.

5. rm 

If you want to delete a directory and all the files in it, you can use the rm command.

Meanwhile, for those of you who want to delete one file in particular, you can add the name of the file after the rm command (example: rm filename).

Not only that, you can also delete multiple files at the same time by writing rm filename1 filename2 filename3.

6. cat

As the name suggests, the cat (concatenate) command is used to concatenate files.

For example, write cat filename1 filename2>filename3 to concatenate filename1 and filename2, and make them filename3.

In addition, cat also offers several other functions, such as knowing the contents of a file (example: cat file.txt) and creating a new file (example: cat > newfile).  

7. echo

The echo command offers many functions, one of which is to insert data (which is usually in the form of text) into a file.

For example, you want to add the text hello there, welcome! to a file called sample.txt. So to do this, you can write echo hello there welcome! >> sample.txt

8. ls

For those of you who want to know what content is in the working directory or active directory, you can use the ls command.

In addition, you can also view hidden files with the command ls -a, or view the contents of other directories by typing the directory name such as ls /home/username/Documents.

9. locate

You are confused about where a file is stored? Don't worry, you can use the locate command.

If you forget the name of the file, you can add -i, so the command becomes locate -i filename.

Meanwhile, if the filename being searched for is more than one word, you need to add an asterisk ( * ) to the command (example: locate -i data*school ).   

10. find

You can also use the find command to find a file or directory. The difference is, the search with this command will only be focused on certain directories.

For example, if you write find /directoryname/ -name sample.txt, the search will only be performed on the specified home directory.

11. touch

The touch command can be used to create new files with various types of formats; such as txt, zip, and html.

To create a text file in the Documents directory, for example, you can write the command touch /home/username/Documents/sample.txt.

12. sudo

Abbreviation for SuperUser Do; sudo is a basic Linux command that allows you to perform a variety of tasks that require root or administrative permissions.

An example of the command is sudo visudo, which is used to edit configuration files or sudoers.

13. cp

The cp command is used to copy files from the active directory to another directory. For example, you want to copy sample.txt to the Documents directory.

Well, you could write cp sample.txt /home/username/Documents/.

14. mv

In Linux operating system, you can also move files to other directories with the help of the mv command.

For example, you write mv sample.txt /home/username/Documents/ to move sample.txt to the Documents directory.

Not only that, mv can also be used to rename files. For example, if you want to rename your txt file, the command would be mv oldsample.txt newsample.txt.  

15. ping

Often hear the ping command? Or even use it often? This basic Linux command offers a function to find out or check your connection to the server.

If you write ping google.com, for example, you will later get detailed information about your connection to Google. 

16. zip and unzip

The zip and unzip commands must be familiar to your ears. The zip command is used to compress files into zip archives.

An example command would be zip -r archivename.zip filename1 folder2. In contrast, unzip works to extract zip archives (example: unzip archivename.zip ). 

17. hostname

There is some information you can get from this hostname command. One of them is about DNS (Domain Name System).

Also, you can find your IP address by adding -i or -I, so the command becomes hostname -i or hostname -I.   

18. chown

Did you know that every file in Linux is equipped with security and protection in the form of access permissions? This means that each file and directory can only be accessed by certain users. 

There are three classifications of user permissions in Linux: 

  • User — the owner of the file or the user who created the file
  • Group — consisting of multiple users. Later, only group members can access the files. 
  • Others — users who have access to a file, but are neither the user/owner nor a member of the group. 

So, what if you want to change or transfer ownership of a file? It's easy, by using the chown command.

For example, if you write chown user2 sample.txt, you mean that you have made user2 the owner of the sample.txt file.

In addition, chown can also be used to change the ownership of a group (example: chown:group1 sample.txt).

19. chmod

The chmod (change mode) command is used to change access permissions to a file or directory. The command sequence is chmod [access permission options] [filename] .

Examples like chmod 754 filename

The 754 in the code can be detailed as follows:

  • 7 is a combination of 4+2+1; which means that the user can read (number 4 ), modify and delete (number 2 ), and run/execute the file (number 1 ). 
  • 5 is a combination of 4+0+1; indicates that group members can read (4) and run/execute files (1), but cannot modify and delete them (0).
  • 4 is a combination of 4+0+0, which means that others can only read (4), but cannot modify or delete (0) and run files (0).

20. uname

The uname or Unix Name command is used to find basic information about the Linux system you are using, such as kernel version, release date, processor type, operating system name, and so on. 

The command pattern is uname [option] . Later, you will change [options] according to the information you want to find. For example, to know the name of the operating system you are using, you can write uname -o.     

21. df 

Use the df command to get information about your system's disk space usage, as well as how much space you have left.

These details will be presented in percentages and kilobytes. However, if you want to see it in megabytes, then write the command df -m.

22. diff 

The diff (short for difference) command is used to compare contents between files, line by line.

Interestingly, you will get information about which lines need to be changed to make the files the same.

To run this command, you just need to write diff followed by the name of the file to compare (example: diff file1.txt file2.txt ). 

As output, you will get a symbol containing instructions on how to change the first file to resemble the second file.

The symbols consist of a (add/add), c (change/change), and d (delete/delete).      

23. du 

You can track or check how much disk space is being used by files and directories with the help of the du (disk usage) command.

For example, you want to find out the disk usage of the /home/username directory. Well, you can simply write du /home/username.

Meanwhile, if you want to see the results in bytes, kilobytes, megabytes, gigabytes and so on, then add -h so that it becomes du -h /home/username.     

24. tar

The tar command is actually pretty much the same as zip. The difference is, tar only collects files in one archive with the extension .tar or tarball, without compressing them like in zip.

The command pattern is tar [options] [archive name] [file or directory to be archived]

For example, you write the command tar -czvf filename.tar.gz /home/username/. Here, the option you're using is czvf, which means:

  • c = create a new .tar archive
  • z = create an archive with gzip compression
  • v = verbose/show tar file creation progress
  • f = create a tar archive with the given name, which in this example is filename.tar.gz

25. grep

grep is one of the most used basic Linux commands. Its function is to search for text or patterns in a file. The command pattern is grep [options] text/pattern [files]

For example, you wrote the command grep -i UNIX sample.txt. That means you're looking for the word UNIX in the sample.txt file.

The -i option means that the search will display all lines containing the UNIX word in case insensitive mode, regardless of whether the word is written in uppercase or lowercase. So that the word UNIX, Unix, or unix will later be displayed in search results.

26. kill

If a program you are running on Linux is unresponsive or is found to be using excessive system resource capacity, why not just stop the process. To do this, you can use the kill command.

Interestingly, there are more than 60 signals that can be used in this command. To find out, you can write the command kill -l

Among these signals, the two most widely used options are (15) SIGTERM (stops the program and gives time to save its progress ) and (9) SIGKILL (force kills the program without recording any unsaved progress ).

An example of the command is kill -9 1223. Here, 1223 is the PID (Process ID) that you want to kill. You can find the PID of the process you want to kill in the command top or ps (example: ps -A | grep 'firefox' )

27. man

Are you still confused with some commands and want to learn more about their functions?

Don't worry! Linux also provides the man command, a command that will display a man page with instructions or a description of a particular command.

To do this, simply write the command man followed by the name of the command you want to know (example: man rmdir).

Conclusion

In this article, you've learned the 27 most commonly used basic Linux commands. All of these commands will certainly help you operate a task on Linux with ease.

Furthermore, if you already understand and are familiar with the basic Linux commands, you can learn other Linux commands so that you can run the operating system more efficiently.

Harbyjay Official
Harbyjay Official
https://jirale.com
I am a web designer and developer. Sharing knowledge is my passion and web designing is my interest but it is not bigger than my interest in Islam.

1 comment