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.

    [php] history [/php]

  2. Search in command history: Lets say you want to search a specific keywords in previously runned commands. then you have to run:

    [php] history | grep search_term [/php]

  3. Write in a file: You can write a text in a file by running below command

    [php] echo "Hello world!" > hello.txt [/php]

    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

    [php] touch test.txt [/php]

  5. Install new package: For install new package, apt install command is used. eg: apt install package_name

    [php] apt install git [/php]

    [php] apt install ftp[/php]

  6. Remove package: To remove an installed package, you have to run:

    [php] apt purge *git* [/php]

    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:

    [php] service service_name start [/php]

    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

    [php] systemctl enable service_name [/php]

    Note: eg: systemctl anable ssh

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

    [php] service service_name stop [/php]

    Note: eg: service apache2 stop

  10. Stop any startup service: To disable a startup service, you have to run:

    [php] systemctl disable service [/php]

  11. Check Service Statuses: Check service all service status :

    [php] service –status-all [/php]

    Note: Running service will have “+” sign

  12. Restart a service: To restart any serice:

    [php] systemctl restart service_name [/php]

  13. Check service status: If you want to check any service status, run:

    [php] systemctl status service_name [/php]

    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

    [php] systemctl reload service_name [/php]

    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

    [php] systemctl reload-or-restart service_name [/php]

    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:

    [php] chmod +x script [/php]

    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:

    [php] exit [/php]

    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:

    [php] shutdown [/php]

    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:

    [php] unzip[/php]

    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

    [php] htop [/php]

  21. Terminate any process: If any app is unresponsive, you can use “kill” command with process ID or application binary name. Such as:

    [php] kill chrome [/php]

    [php] kill process_id[/php]

  22. Remove a file and make it unrecoverable: To remove any file and make it unrecoverable, you have to run below command:

    [php] shred file_name.extension [/php]

    Note: Be cautious before running this file

  23. Print current user: To print current user, just run:

    [php] whoami[/php]

  24. Get location of any app: Get location of any app, run “where” command. eg:

    [php] where php [/php]

  25. Get word count of a text file:To get word count of a text file, run below command::

    [php] wc text_file.txt[/php]

    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

    [php] apt update && apt upgrade [/php]

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!