DEV Community

Sumit Jadiya
Sumit Jadiya

Posted on

Linux Commands CheatSheet

Basic Commands

  • whoami -> displays the name of logged in user

  • clear -> clear the terminal

  • mkdir -> create new directory [syntax - mkdir new_directory]

  • pwd -> present working directory [syntax - pwd]

  • ls -> list all the files and folders in current directory [syntax - ls]

  • cd -> Change directory [syntax - cd /Desktop]

    • cd .. -> previous directory
    • cd ~/ -> root directory
  • touch -> create new file without content [syntax - touch new_file.txt]

  • cat -> display file content [syntax - cat new_file.txt]

    • cat > newfile.txt -> create a new file and edit the content
  • mv -> Move file to new directory [syntax - mv file filepath]

    • mv filename new_file_name -> rename the file/directory
  • rm -> remove file/directory [syntax - rm file.txt]

    • rm -r -> remove recursively
    • rm -rf -> remove content recursively and forcefully
    • rmdir -> remove directory
  • history -> prints all the previous commands typed in current terminal session

  • sudo -> allow user to run program as root

  • grep -> global search for regular expression [syntax - grep [options] pattern [files]]

    • grep -c “sumit” samplefile.txt -> counts the number of lines that have "sumit"
    • grep -i "SuMiT" samplefile.txt -> this will search for the string insensitively in given file
    • grep -l "file" * -> all files that contains the given string/pattern in diretory
    • grep -w "hello" * -> check for the whole word in a file
    • grep -n "unix" * -> show line number while displaying the output

Top comments (0)