Day 12 - Cheatsheet for Linux and Git

Pavan PawarPavan Pawar
3 min read

๐Ÿ”– Linux Commands

  1. To create an empty file

     touch <filename>
    
  2. To create multiple files

     touch file{1..5}.txt
    
  3. List all the files including hidden files also

     ls -la
    
  4. create a nested directory

     mkdir -p a/b/c/d/e
    
  5. To view a file

     cat file.txt
    
  6. To add output to the file

     echo "pavan" > file1.txt
    
  7. To view the history of commands

     history
    
  8. To remove a file

     rm file1.txt
    
  9. To remove a file as nested

     rm -r A
    
  10. To open a text editor

    vim file1.txt
    
  11. To show starting 2 records of the file

    head -2 file1.txt
    
  12. To show the last 2 records of the file

    tail -2 file1.txt
    
  13. To add a user

    sudo useradd pavan
    
  14. To add a user by creating a directory

    sudo useradd -m pavan
    
  15. To copy a file from one folder to another

    cp folder1/testfile.txt folder2/
    
  16. To move a file from one folder to another

    mv folder1/file1.txt folder2/
    
  17. To view all users

    sudo cat /etc/passwd
    
  18. To switch user

    su pavan
    
  19. To create a password for the user

    sudo passwd pavan
    
  20. To exit from the user

    exit
    
  21. To update packages

    sudo apt update
    
  22. To Upgrade packages

    sudo apt upgrade
    
  23. To install packages

    sudo apt install docker.io
    
  24. To uninstall packages

    sudo apt purge docker.io
    

๐Ÿ”– Git Commands

  1. To initialize a repository

     git init
    
  2. To add changes from untracked to stage

     git add .
    
  3. To commit the changes

     git commit -m "commit message"
    
  4. To show the status of VCS

     git status
    
  5. To restore deleted file

     git restore <filename>
    
  6. To view a log of the file

     git log
    
  7. To view the logs of files in a One-line

     git log --oneline
    
  8. To reduce the length of the hashcode

     git log --oneline --pretty
    
  9. To add a username

     git config --global user.name "username"
    
  10. To add an email

    git config --global user.email "email"
    
  11. To create a new branch

    git checkout -b dev
    
  12. To switch to a new branch

    git checkout dev
    
  13. To show the status of the branch

    git branch
    
  14. To get remote repo to local

    git pull origin main
    
  15. To add changes from the local to the remote repo

    git push origin main
    
  16. To delete unwanted commit from log

    git revert <commit ID>
    
  17. To reset the file to the previous version

    git reset <commit ID>
    
  18. To ignore the files which don't want to track

    gitignore
    
  19. To merge a branch

    git merge dev
    
  20. To reduce the commit history

    git --squash
    
  21. To maintain remote and local history in a linear manner

    git --rebase master
    
  22. To pick any specific commit ID

    git cherry-pick <commit ID>
    
  23. To save the working directory at the temp location without committing

    git stash
    
  24. To get back the file from the temp location.

    git stash pop
    
6
Subscribe to my newsletter

Read articles from Pavan Pawar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pavan Pawar
Pavan Pawar