top 25 linux command that every developer should know

Linux is a Unix-like, open-source, and community-developed operating system for computers, servers, mainframe computers, and embedded devices. It is supported on almost every major computer platform which makes it one of the most widely supported operating systems.

Most people think Linux is a very complicated operating system in general use or it’s only for programmers because people fear command line arguments (CLI).

In general using of a command-line interface is more powerful and effective. Tasks that require a multi-step process through GUI can be done in a matter of seconds by typing commands into the CLI.

Anyone is thinking about using Linux or any other Linux distribution like Ubuntu, CentOS, or Fedora. They must know some basic or command commands of Linux which help them to perform daily operations. Below are basic commands and their use :

1. pwd command

pwd command is a built-in command that prints the full path of the working directory from the root. PWD stands for Print Working Directory. i.e. /home/username

pwd command has 2 flags :

  • pwd -L: Prints the symbolic path.
  • pwd -P: Prints the actual path.

2. ls Command

The ls command is used to view the contents of a directory. By default, it will use the current working directory. You can also pass another directory path as parameter. The ls command is slimmer than the Dir command in Windows.

There are a few variations for ls command :

  • ls -R: It will list all files and folders.
  • ls -a: It will list all hidden files.
  • ls -al: It will list files directly with other information like permission, file size, and more.

3. cd Command

The cd command is used to navigate through directories and files in CLI. This command requires pass as a parameter which can be a full path or directory name based on your working directory.

There are some shortcuts to help you to use cd command effectively :

  • cd .. : It will move one directory up.
  • cd : It will take you straight to the home folder.
  • cd- : It will take you to the previous directory

4. cat command

The cat (concatenate) is one of the most commonly used commands. It is used to list the contents of a file on the standard output. It’s also used to create new file.

This command requires a file name with its extension as a parameter. i.e. cat file.txt.

To create a new file with the cat command you can use this example: cat > file.txt.

It can also used to join two files. i.e. cat filename1 filename2>filename

5. cp command

The cp command is used to copy files from one directory to another. For example, the command cp text.txt /home/username/myfiles will copy a file to the myfiles directory.

6. mv command

The mv command is used to move files from one directory to another. We can also use the mv command to rename files.
The use of the mv command is similar to the cp command. For example mv file.txt /home/username. To use the mv command to rename a file, we need to pass a new file name as a second flag like this: mv file.txt file1.txt.

7. grep command

Find text in a file. The grep command searches through many files at a time to find a piece of text you are looking for. i.e. grep ‘search_term’ file.txt. It will search the file and return details about the search result.

8. sudo command

Sometimes there is a need to specify rights to perform some actions like installing applications you need to System Administrator rights. When you give any commands with sudo command then it will perform that task with high priority and as super admin.

For example, you have logged in from a general user who doesn’t have the right to perform application installation. But with the sudo command, you can perform that task.

sudo apt-get install package_name

9. shutdown Command

As per the name shutdown, the command suggests powering off the system. But with the shutdown command, you can perform a delay into shutdown or reboot the system as per your requirements.

Below are some examples of shutdown commands:

shutdown now

//Shutdown at specific time
shutdown 15:44

//cancel previous shutdown
shutdown -c

//To reboot system
sudo shutdown -r now

10. mkdir command

While working with files, sometimes we need to create directories. you can create a directory/folder using the mkdir command. mkdir stands for make directory.

Here we just need to pass the directory name as a parameter like below example :

mkdir test

11. rm command

The rm command is used for removing files and directories from our system. You need to be careful while using this command because it’s very difficult to recover files deleted this way.

Below are some examples of the rm command :

rm test.txt

//remove directory
rm -r test/

//remove directory with it's content forcefully
rm -rf test/

12. man command

The man command displays manual information about another command, like help. To see the manual details on any command you need to pass the command name as a parameter like the below:

man man
//or
man rm

13. touch command

The touch command allows you to create a blank new file through the Linux command line. The touch command is also used for updating the timestamp information of a file.

touch text.txt
//or
touch -m text.txt

14. chmod command

The chmod command allows you to change file permissions. It has lots of sub-options available but basic permissions are read, write, and execute.

One of the most common uses of chmod is to make a file executable by the user. To do that you need to use the +x flag.

chmod +x text

15. exit command

The exit command works as per the name, it will end the shell session of your terminal and automatically closes the current terminal.

16. locate command

The locate command works just like the window’s search command. It will search files on a system. By default it’s case-sensitive but you can pass -i to make it case-insensitive. i.e. locate -i test will search a file with a test in its name.

17. unzip command

This command will help you to unzip files in zip format. This package is not pre-installed so make sure you have installed it before using it.

Below is an example command to unzip a file :

unzip test.zip

18. apt, yum, Pacman command

In Linux package managers are used to install or uninstall packages. So at some point of work, you need to use those package managers. Generally, package managers are based on Linux distribution.

Debian-based systems like Ubuntu or Linux-mint use apt by default. Whereas in Fedora or CentOS, yum is used for installation. while Arch-based systems like Arco Linux or Manjaro use Pacman as their package manager.

Below are some examples of installing gimp on different Linux distributions:

sudo apt install gimp
sudo yum install gimp
sudo pacman -S gimp

19. echo command

The echo command prints text into a terminal. The primary use of echo is to print environment variables but we can use it as per our requirement like showing some information while the shell script is running.

20. kill command

Generally using a system with low configuration some programs become unresponsive and can not be closed by GUI. Then we can forcefully close its process with the kill command.

In simple words kill command sends a specific program close request to the system. Here we can use PID (process ID) or the program’s binary name.

21. ping command

The ping is the most popular networking terminal utility used to test network connectivity. ping has a ton of options, but in most cases, you’ll use it to request a domain or IP address.

The ping command accepts either an IP address or domain name of a particular server or website. like below example

ping google.com
ping 142.250.199.142

22. diff command

As the name suggests diff stands for the difference. The diff command is used to check the difference between two files. Here it will take two full names of a file as a parameter. i.e. diff text1.txt text2.txt.

The diff command will compare both files line by line and print lines that do not match.

23. chown command

In Linux, all files are owned by a specific user. The chown command enables you to change or transfer the ownership of a file to the specified username. For example, chown user_name text.txt will transfer text file ownership to a given user.

24. whoami command

The whoami command displays the username currently in use.

25. Additional Commands

  • To clear the terminal use the clear command.
  • TAB can be used for auto-fill data while writing.
  • To stop the currently executing script, you can use either ctrl+C or ctrl+Z. It will automatically stop command execution.
  • You can run multiple commands using a semi-colon(;).