Day 12 - Cheatsheet for Linux and Git
Table of contents
๐ Linux Commands
To create an empty file
touch <filename>
To create multiple files
touch file{1..5}.txt
List all the files including hidden files also
ls -la
create a nested directory
mkdir -p a/b/c/d/e
To view a file
cat file.txt
To add output to the file
echo "pavan" > file1.txt
To view the history of commands
history
To remove a file
rm file1.txt
To remove a file as nested
rm -r A
To open a text editor
vim file1.txt
To show starting 2 records of the file
head -2 file1.txt
To show the last 2 records of the file
tail -2 file1.txt
To add a user
sudo useradd pavan
To add a user by creating a directory
sudo useradd -m pavan
To copy a file from one folder to another
cp folder1/testfile.txt folder2/
To move a file from one folder to another
mv folder1/file1.txt folder2/
To view all users
sudo cat /etc/passwd
To switch user
su pavan
To create a password for the user
sudo passwd pavan
To exit from the user
exit
To update packages
sudo apt update
To Upgrade packages
sudo apt upgrade
To install packages
sudo apt install docker.io
To uninstall packages
sudo apt purge docker.io
๐ Git Commands
To initialize a repository
git init
To add changes from untracked to stage
git add .
To commit the changes
git commit -m "commit message"
To show the status of VCS
git status
To restore deleted file
git restore <filename>
To view a log of the file
git log
To view the logs of files in a One-line
git log --oneline
To reduce the length of the hashcode
git log --oneline --pretty
To add a username
git config --global user.name "username"
To add an email
git config --global user.email "email"
To create a new branch
git checkout -b dev
To switch to a new branch
git checkout dev
To show the status of the branch
git branch
To get remote repo to local
git pull origin main
To add changes from the local to the remote repo
git push origin main
To delete unwanted commit from log
git revert <commit ID>
To reset the file to the previous version
git reset <commit ID>
To ignore the files which don't want to track
gitignore
To merge a branch
git merge dev
To reduce the commit history
git --squash
To maintain remote and local history in a linear manner
git --rebase master
To pick any specific commit ID
git cherry-pick <commit ID>
To save the working directory at the temp location without committing
git stash
To get back the file from the temp location.
git stash pop
Subscribe to my newsletter
Read articles from Pavan Pawar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by