Useful Linux Commands Part 2

50 useful Linux Commands – Part 2

50 useful Linux Commands – Part 2

Hello everyone, in this two part tutorial, we will learn some very basic and useful Linux commands. So lets get started. For Part-1, check here


  1. Check command history : “history” command is used viewing all the previous command.
  2. Search in command history: Lets say you want to search a specific keywords in previously runned commands. then you have to run:
     history | grep search_term 
  3. Write in a file: You can write a text in a file by running below command
     echo "Hello world!" > hello.txt 

    Note: This command will create a file named “hello.txt” inside “Hello World!” written in it.

  4. Create new file: For creating a new file, below command is used: eg: touch filename.filetype
     touch test.txt 
  5. Install new package: For install new package, apt install command is used. eg: apt install package_name
     apt install git 
     apt install ftp
  6. Remove package: To remove an installed package, you have to run:
     apt purge *git* 

    Note: cp is copy command, then file name, finally directory where you want to copy the file

  7. Start a service: If you want to run/start any service, you have to run below command:
     service service_name start 
    eg: service apache start
  8. Start a service at start up: To start or run a service in startup, you have to use “systemctl” command
     systemctl enable service_name 

    Note: eg: systemctl anable ssh

  9. Stop any service: To stop any service, you have to run
     service service_name stop 

    Note: eg: service apache2 stop

  10. Stop any startup service: To disable a startup service, you have to run:
     systemctl disable service 
  11. Check Service Statuses: Check service all service status :
     service --status-all 

    Note: Running service will have “+” sign

  12. Restart a service: To restart any serice:
     systemctl restart service_name 
  13. Check service status: If you want to check any service status, run:
     systemctl status service_name 

    Note: You have to run this command as super admin

  14. Reload a service: If you want to reload any service without restarting it, only reload the configurations, run below command
     systemctl reload service_name 

    Note: After running the command, you have to provide user name, password and password confirmation

  15. Reload or restart: If you are not sure wheather to reload or restart, run below command, it will check itself if new configuration to load or to restart the service
     systemctl reload-or-restart service_name 

    Note: Here we reading the “/etc/passwd” file, which contains all users info.

  16. Change permission: “chmod” command is use to provide specific access to a file or folder. Afile may have read (r), write(w) or execute (x) permission. If you want to give execute permission to a file, you have to run:
     chmod +x script 

    Note: Be careful of this file. Do not give full access to this file for security reason.

  17. Exit terminal: For exit the current shell terminal, you have to run:

    Note: Such as, if you want to switch to user jhon, run “su john

  18. Turn off machine: If you want to turn off the machine, just run:

    Note: The default shutdown time is one minute, if you want to shutdown immediately, type: “shutdown now

  19. Unzip a zipped folder: To unzip/extract the contents of any zip folder, you have to run below command:

    Note: It will provide Interface Configuration related data

  20. Show Processes: If you want to check running processes, you should use “htop” command. It may not be installed by default. Then just install it by typing “y
  21. Terminate any process: If any app is unresponsive, you can use “kill” command with process ID or application binary name. Such as:
     kill chrome 
     kill process_id
  22. Remove a file and make it unrecoverable: To remove any file and make it unrecoverable, you have to run below command:
     shred file_name.extension 

    Note: Be cautious before running this file

  23. Print current user: To print current user, just run:
  24. Get location of any app: Get location of any app, run “where” command. eg:
     where php 
  25. Get word count of a text file:To get word count of a text file, run below command::
     wc text_file.txt

    Note: cp is copy command, then file name, finally directory where you want to copy the file

  26. Update Packages list and Upgrade Packages: If you want to update all the packages list and also upgrade all the packages in one single command, you have to run
     apt update && apt upgrade 

That’s all for today. In the first part, you will get 25 more basic Useful Linux commands. Keep learning folks!

Editorial Staff

A Learner and trying to share what I learned!