Common linux command you 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 of people think Linux is very complicated operating system in general use or it's only for programmers, because people are afraid of command line arguments (CLI).

In general use 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, 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 built-in command which prints full path of working directory from root. PWD stands for Print Working Directory. i.e. /home/username

pwd command has 2 flags :

  1. pwd -L : Prints the symbolic path.
  2. 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 current working directory. You can also pass other directory path as parameter. The ls command is slimier to Dir command in windows.

There are few variation for ls command :

  1. ls -R : It will list all files and folders.
  2. ls -a : It will list all hidden files.
  3. ls -al : It will list files and 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 parameter which can be full path or directory name based on your working directory.

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

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

4. cat command

The cat (concatenate) is one of the most conmanly 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 require file name with it's extension as parameter. i.e. cat file.txt.

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

It can also used for join two files. i.e. cat filename1 filename2>filename3

5. cp command

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

6. mv command

The mv command is used to move files from one directory to another. We can also use mv command to rename files.

The use of mv command is similar to cp command. For example mv file.txt /home/username. To use mv command to rename file, we need to pass new file name as 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 file and returns details about search result.

8. sudo command

Sometimes there is need to specif rights to perform some actions like installing application 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 general user who don't have right to perform application installation. But with sudo command you can perform that task.

    
sudo apt-get install package_name
    

9. shutdown Command

As per name shutdown command suggest to power off system. But with shutdown command you can perform delay into shutdown or reboot system as per your requirements.

Below are some examples of shutdown command :

    
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 directory/folder using mkdir command. mkdir stands for make directory.

Here we just need to pass directory name as 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 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 with that command. To see the manual information about any command you need to pass command name as parameter like 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 also used for updating timestamp information of 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 use of chmod is to make a file executable by the user. To do that you need to use +x flag.

    
chmod +x text
    

15. exit command

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

16. locate command

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

17. unzip command

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

Below is example command to unzip file :

    
unzip test.zip
    

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 manage. Generally package managers are based on Linux distribution.

Debian-based systems like ubuntu or linux-mint uses apt by default. Where in Fedora or CentOS, yum is used for installation. while in Arch-based systems like Arco linux or Manjaro use pacman as their package manager.

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

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

18. echo command

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

19. kill command

Generally using system with low configuration some programs become in-responsive and can not be closed by GUI. Then we can forcefully close it's process with kill command.

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

20. 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 accpt either IP address or domain name of particular server or website. like below example

    
ping google.com
ping 142.250.199.142
    

21. diff command

As per name suggest diff stands for difference. The diff command is used for check difference between two file. Here it will take two full name of file as parameter. i.e. diff text1.txt text2.txt.

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

22. 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 given user.

23. wget command

If you are downloading lots of content from internet then wget command is very useful. The wget command take url as parameter and download content from that user. Generally it's used to download softwares.

24. whoami command

The whoami command displays the username currently in use.

25. useradd, userdel command

Linux is multi-user system and sometimes more than one person is using same system. With useradd and userdel command user access become simplier.

The useradd command used for adding user to system. While userdel command used for deleting existing user from system.The both commands useradd and userdel need user name as parameter.

Tips and tricks

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

Share your thoughts

Ask anything about this examples