Day-12: LINUX &GIT-GITHUB CHEAT SHEET

Hello there! I'm a DevOps enthusiast who's always eager to learn more about the exciting world of automation and deployment. I may not be on the job yet, but I'm always tinkering with tools and technologies to improve my skills. When I'm not busy studying or practicing, you can find me exploring the great outdoors or binge-watching my favorite tech tutorials. Let's learn and grow together!
File Commands
⦁ ls --> Directory listing.
⦁ ls -al --> Formatted listing with hidden files.
⦁ ls *.sh --> list all the files having .sh extension.
⦁ ls -i --> list the files and directories with index numbers inodes.
⦁ ls -d */ --> list only directories.(we can also specify a pattern).
⦁ ls -lt --> Sorting the Formatted listing by time modification.
⦁ cd dir --> Change directory to dir.
⦁ cd --> Change to the home directory.
⦁ cd - --> Go to the last working directory.
⦁ cd .. --> change directory to one step back.
⦁ cd ../.. --> Change directory to 2 levels back.
⦁ pwd --> Show the current working directory.
⦁ mkdir dir --> Creating a directory dir.
⦁ cat >file -->Places the standard input into the file.
⦁ more file --> Output the contents of the file.
⦁ head file --> Output the first 10 lines of the file.
⦁ tail file --> Output the last 10 lines of the file.
⦁ tail -f file --> Output the contents of a file as it grows, starting with the last 10 lines.
⦁ touch file -->Create or update file.
⦁ rm file --> Deleting the file.
⦁ rm -r dir --> Deleting the directory.
⦁ rm -f file --> Force to remove the file.
⦁ rm -rf dir --> Force to remove the directory dir.
⦁ cp file1 file2 --> Copy the contents of file1 to file2.
⦁ cp -r dir1 dir2 --> Copy dir1 to dir2; create dir2 if not present.
Process management
⦁ ps --> To display the current working processes.
⦁ top --> Display all running processes.
⦁ kill pid --> Kill the process with given pid.
⦁ killall proc --> Kill all the process named proc.
⦁ pkill pattern --> Will kill all processes matching the pattern.
⦁ date --> Show the current date and time.
⦁ cal --> Show this month's calendar.
⦁ uptime --> Show current uptime.
⦁ w --> Display who is online.
⦁ whoami --> Who you are logged in as.
⦁ uname -a --> Show kernel information.
⦁ man --> command Show the manual for command.
⦁ df --> Show the disk usage.
⦁ du --> Show directory space usage.
⦁ free --> Show memory and swap usage.
⦁ whereis app --> Show possible locations of app.
⦁ which app --> Show which applications will be run by default.
Searching
⦁ grep pattern --> file Search for pattern in file.
⦁ grep -r pattern dir --> Search recursively for pattern in dir.
⦁ command | grep pattern --> Search pattern in the output of a command.
⦁ locate file --> Find all instances of file.
⦁ find . -name filename --> Searches in the current directory (represented by a period) and below it, for files and directories with names starting with filename.
File permission
⦁ r --> read permission
⦁ w --> write permission
⦁ x --> execute permission
⦁ chmod 777 filename --> Assign read, write, and execute permission to everyone.
⦁ chmod -R 777 dirname --> Assign full permission to the directory and all sub- directories.
⦁ chmod 766 filename --> Assign full permission to the owner, and read and write permission to group and others.
⦁ chown username filename --> Change the ownership of a file.
⦁ chrgp groupname filename --> Change group ownership of a file.
User Management Commands
⦁ sudo useradd username --> To add a new user.
⦁ sudo passwd -l username --> To change the password of a user.
⦁ sudo userdel -r username --> To remove a newly created user.
⦁ sudo usermod -a -G groupname username --> To add a user to a group.
⦁ sudo userdel user groupname --> To remove a user from a group.
Compression
⦁ tar cf --> file.tar file Create tar named file.tar containing file.
⦁ tar xf file.tar --> Extract the files from file.tar.
⦁ tar czf file.tar.gz files --> Create a tar with Gzip compression.
⦁ tar xzf file.tar.gz --> Extract a tar using Gzip.
⦁ tar cjf file.tar.bz2 --> Create tar with Bzip2 compression.
⦁ tar xjf file.tar.bz2 --> Extract a tar using Bzip2.
⦁ gzip file --> Compresses file and renames it to file.gz .
⦁ gzip -d file.gz --> Decompresses file.gz back to file.
Network
⦁ ping host --> Ping host and output results.
⦁ whois domain --> Get whois information for domains.
⦁ dig domain --> Get DNS information for domain.
⦁ dig -x host --> Reverse lookup host.
⦁ wget file --> Download file.
⦁ wget -c file --> Continue a stopped download.
Git-GitHub Cheat-Sheet
*Git config
Get and set configuration variables that control all facets of how Git looks and operates.
Set the name:git config --global user.name "UserName"
Set the email:git config --global user.email "yourEmail@gmail.com"
Check the setting:git config global --list
*Initializing a repository
git init
*Staging files
git add file1 --> Stages a single file
git add file1 file2 --> Stages multiple files
git add . --> Stages the current directory and all its content
*Viewing the status
git status
*Committing the staged files
git commit -m “Message”
*Skipping the staging area
git commit -am “Message”
*Removing files
git rm file --> Removes from working directory and staging area
git rm --cached file --> Removes from staging area only
*Renaming or moving files
git mv file file1.txt
*Viewing the staged/unstaged changes
git diff --> Shows unstaged changes
git diff --staged --> Shows staged changes
git diff --cached --> Same as the above
*Viewing the history
git log --> Full history
git log --oneline --> Summary
git log --reverse --> Lists the commits from the oldest to the newest
*Unstaging files (undoing git add)
git restore --staged file
*Comparing commits
git diff HEAD~2 HEAD --> Shows the changes between two commits
*Viewing a commit
git show 921a2ff --> Shows the given commit
git show HEAD --> Shows the last commit
git show HEAD~2 --> Two steps before the last commit
Branching & Merging
*Managing branches
git branch dev --> Creates a new branch dev
git checkout dev --> Switches to the dev branch
git checkout -b dev --> Creates and switches to dev branch
git branch -d dev --> deletes the dev branch
*Stashing
git stash --> Creates a new stash
git stash list --> Lists all the stashes
git stash show stash@{1} --> Shows the given stash
git stash apply 1 --> Applies the given stash to the working dir
git stash drop 1 --> Deletes the given stash
git stash clear --> Deletes all the stashes
*Merging
git merge dev --> Merges the dev branch into the current branch
git merge --squash dev --> Performs a squash merge
*Viewing the merged branches
git branch --merged --> Shows the merged branches
git branch --no-merged --> Shows the unmerged branches
*Rebasing
git rebase master --> Changes the base of the current branch
*Cherry picking
git cherry-pick fed53ed --> Applies the given commit on the current branch
Collaboration
*Cloning a repository
git clone url
*Syncing with remote
git fetch origin master --> Fetches master from origin
git fetch origin --> Fetches all objects from origin
git pull --> Fetch + merge
git push origin master --> Pushes master to origin
*Managing remote
git remote --> Shows remote repos
git remote add upstream url --> Adds a new remote called upstream
git remote rm upstream --> Removes upstream
Rewriting History
*Undoing commits
git reset --soft HEAD --> Removes the last commit, keeps changes staged
git reset --mixed HEAD --> Unstages the changes as well
git reset --hard HEAD --> Discards local changes
*Reverting commits
git revert 72856ea --> Reverts the given commit
git revert HEAD~3 --> Reverts the last three commits
*Amending the last commit
git commit --amend
*Interactive rebasing
git rebase -i HEAD~5
\>>>>>>>>>>>>>>>>> Thank you for reading! :-) <<<<<<<<<<<<<<<<



