1. pwd (print working directory)

  2. ls (list)
    #without argument curr directory
    ls
    #with argument
    ls DIRECTORY
    
  3. cd (change directory)
    #without argument home directory
    cd
    #with argument
    cd DIRECTORY
    # back
    cd ..
    
  4. mv (move or rename)
    #move
    mv FILE_OR_DIRECTORY_NAME  NEW_DIRECTORY
    #rename
    mv FILE_OR_DIRECTORY_NAME  NEW_FILE_OR_DIRECTORY_NAME
    
  5. cp (copy)
    #same directory
    cp ORIGINAL_FILENAME  NEW_FILENAME
    #another directory
    cp ORIGINAL_FILENAME  DIRECTORY
    #copy directory
    cp -r ORIGINAL_DIRECTORY  NEW_DIRECTORY
    
  6. cat (concatenate - prints the contents of a file)
    cat FILENAME
    
  7. rm (remove)
    #delete
    rm FILENAME
    #delete all
    rm  *
    #non-empty directory
    rm -r DIRECTORY_NAME
    
  8. mkdir (make directory)
    mkdir  DIRECTORY_NAME
    
  9. rmdir (remove directory)
    rmdir  DIRECTORY_NAME
    
  10. print n lines
    #print n lines
    head -n 2 FILENAME
    tail -n 2 FILENAME
    #combine
    head -n 20 FILENAME | tail -n 5
    #watch the file update
    tail -f FILENAME
    
  11. show history
    #show history
    history
    
  12. clear screen
    #clear screen
    clear
    
  13. install / update packages
    #install
    sudo apt-get install packagename
    #update
    sudo apt-get update
    
  14. grep <str> <files> (Find which files contain a certain word)
    grep "some word" *	
    
  15. chmod <opt> <file> (Change file permission)
    #Change file permissions read only
    chmod 644 *.html 
    
  16. ps <opt> (List running process)
    #List all running processes by #ID
    ps aux 
    #List process #ID's running by dhyatt
    ps aux | grep USERNAME	
    
  17. kill <opt> <ID> (kill a process)
    #Kill process with ID #8453
    kill -9 8453	
    
  18. gzip <file>
    #Compress file
    gzip bigfile 
    #Uncompress file
    gunzip bigfile.gz	
    
  19. awk (Pattern search, replace and more)
    #Print the lines which matches with the given pattern.
    awk '/someword/ {print}' FILENAME
    #Print 1st and 4th column
    awk '{print $1,$4}' FILENAME
    #Replace comma by null in 3rd column
    awk '{ gsub(",","",$3); print $3 }' FILENAME
    
  20. diff (Compare files)
    diff FILENAME1 FILENAME2
    
  21. at (Scheduling a job)
    #Schedule a job
    echo "sh backup.sh" | at 9:00 AM
    echo "sh backup.sh" | at now + 30 minutes
    #List the scheduled jobs using atq
    atq
    #Remove scheduled job using atrm
    atrm 3
    
  22. more / less (pagination tool for viewing text files)
    cat FILENAME | more
    
  23. date (print current date)

  24. & (the & informs the shell to put the command in the background)
    sh shell_script.sh &
    
  25. nohup (prevents the command from being aborted automatically when you log out or exit the shell)
    nohup sh shell_script.sh -y &
    
  26. Download a file with wget
    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
    
  27. Download a file with curl
    curl -fsSL -o Miniconda3-latest-MacOSX-x86_64.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
    

Leave a Comment