LINUX: Basic Commands Cheat Sheet

By PNC No comments

In this article, we list down the common commands we usually use in a Linux terminal.

  • cd
    Change directory.  Use this command to move from a directory to another.

    • ex. cd your_home_path/your_project_path
  • cd ..
    (cd with a double dot) Change or move to a directory one level up.

    • For example, you’re in your project path and you want to go to a directory one level up.
      • c:\your_home_path\your_project_path cd..
  • cd –
    (cd with a hyphen) Move to the previous directory.
  • cd /
    (cd with a slash) Move to the main or parent directory.
  • chmod
    Use to change the read, write, execute permissions of a file or a directory.

    • ex. chmod -R 777 your_file.txt
  • chown
    Command used to transfer ownership of a file to another user.

    • ex. chown user2 your_file.txt
  • cp
    Copy command to copy files from a directory to another.

    • ex. cp your_file.txt /new_directory
  • diff
    Use this command to compare files line by line.

    • ex. diff file_one.txt  file_two.txt
  • grep
    Search a text or word in a given file.  This is helpful when you’re looking for a specific term or keyword in a file.

    • ex. grep one your_file.txt
  • locate
    Search a file.

    • ex. locate your_file.txt
  • locate -i
    Search a file but making more specific and case sensitive.

    • ex. locate -i YourFile.txt
  • ls
    View the content of a directory.

    • ex. c:\your_home_path\your_project_path ls
  • mv
    Command used to move a file from one directory to another.  Also useful in renaming.

    • Moving a file to a new directory
      • ex. mv your_file.txt /new_file_directory
    • Renaming a file
      • ex. mv old_filename.txt new_filename.txt
  • mkdir
    Make directory.  Command used to create directory.

    • ex. mkdir YourDirectory
  • pwd
    Command to see the full path of the current working directory or file.

    • ex. c:\your_home_path\your_project_path pwd
  • rmdir
    Remove directory.  Command used for deleting a directory.

    • ex. rmdir YourDirectory
  • sudo
    Short for “SuperUser Do”.  We add this in a command to run it with administrative permission.  NOTE: Not advisable for daily use, unless you’re an administrator of course.

    • ex. sudo rmdir TheDirectory
  • touch
    Create a blank new file.

    • ex. touch /project_path/your_file.txt