Top 20 most used Linux commands

Hello there!! đŸ‘»

If you are searching for mostly commonly used Linux commands as a beginner to linux, then you are at a right place. Before diving into main section, please make a note that Linux is case sensitive because ‘doc’ and ‘Doc’ are different as far as the OS is concerned.

  1. echo “{my string}” : This command prints the string that is passed as an argument.

2. whoami : It outputs the username of the currently logged-in user.

3. hostname : It prints the system’s host name and also you can view the IP address of the system by passing -i argument as hostname -i .

4. pwd : This command stands for print working directory. As the name suggests, it outputs your current working directory.

5. ls -l : Lists all the files and directory present in your current working directory in long format i,e along with the permissions, date, time and size.

  • ls -ltr : lists all files and directories with modification time ( to newest) in reverse order
  • ls <directory_name> : lists all the contents of a directory without having to navigate to it.
  • ls -a : lists all the files and directories including hidden files

6. mkdir {directory_name}: This allows you to create a new directory.

7. cd {directory_name} : cd stands for change directory. Its allows you to change the directory. Here {directory_name} refers to the target directory which you want to navigate from current working directory.

  • cd {directory}/{sub_directory}: This helps you to directly navigate into a directory present inside another directory (commonly referred as subdirectory).

8. touch {file_name} : To create an empty file.

9. nano {file_name} : To create a new file by adding the contents.

10. vi {file_name} : vi (vim ) is the one of the advanced editors that is used in linux.

11. cat {filename} : This commands prints the content of the file.

  • cat > {filename} : It allows to overwrite the content in the target file.
  • cat >> {filename} : With the help of this command, strings can appended to the existing content in the file.

cat /{directory_name}/{file_name} : This outputs the contents of a file within directories without having to navigate to it.

echo “newly added text” >> {filename} will also works for this scenario.

12. find -name {filename} : To search for files or directory.

You can also search for more than one file using wildcard patterns. For example, if you want retrieve all the files that has the string ‘mydoc’ in its filename, try with this command : “ find -name *mydoc* ” .

13. grep “mystring” {filename} : grep stands for global regular expression print. This command allows us to search for a string in file or searching a keyword in any command output.

Pipe operator | : It is used to merge commands in linux where the output of first command serves as input to second command.

grep -i “mystring” {filename} : To Ignore case distinctions in characters while searching in the file.

14. rm {filename} : To delete the specified file.

  • rm -f {filename} : This will ignore nonexistent files and arguments, never prompt.
  • rm -d {directory} : To remove an empty directory.
  • rm -r {directory} : To remove non-empty directories and the files within them recursively.

A file deleted with the rm command is deleted permanently, not moved to any trash folder.

15. adduser {username} : To create a user.

You can also use the command “useradd <username>” to create user, but adduser is more secure than useradd, as it prompts you to set the password in the initial user creation process itself and also sets up user folders, directories, and other necessary functions easily.

userdel <username> : To delete the specified user.

16. id {username} : It prints the userid and groupid of the user.

17. cp {myfile} {copied_myfile} : Copy command (cp) is used to copy a file or directory.

18. mv {file_name} {destination} : Move (mv)command helps you to move a file from one path to another specified path.

mv command also used to rename a file : “mv {myfile} {myrenamedfile}” .

19. alias {shortcut}={command}: This feature allows you to create your own shortcut replacing the original linux command. For example, if I want to use the word ‘rach’ instead of going with ‘ls -l’ for viewing list of files in long format.

20. man {command} : It provides us the user manual for all linux commands which includes command description, options, examples and other information about the command.

Happy Learning!! 😊

Scroll to Top