Linux & Git-GitHub Cheat Sheet
Day 12 : #90DaysOfDevOps Challenge

Linux Cheat Sheet
Basic Commands
Command | Description |
| root user |
| Normal user |
| root directory |
| home directory |
| Lists all files and directories in the present working directory |
| Lists files and directories with detailed information like permissions, size, owner, etc. |
| Navigate to the HOME directory |
| Move one level up |
| To change to a particular directory |
| Move to the root directory |
| Creates a new file |
| Displays the file content |
| Joins two files (file1, file2) and stores the output in a new file (file3) |
| Moves the files to the new location |
| Renames the file to a new filename |
| Allows regular users to run programs with the security privileges of the superuser or root |
| Deletes a file |
| Gives help information on a command |
| Gives a list of all past commands typed in the current terminal session |
| Clears the terminal |
| Creates a new directory in the present working directory or at the specified path |
| Deletes a directory |
| Renames a directory |
| Divides the file into x columns |
| Assigns a header to the file |
| Denotes the file with Line Numbers |
| Prints “c” copies of the File |
| Specifies the name of the printer |
| The command used to install and update packages |
| |
| Command to send email |
| Command to send an email with an attachment |
ls Options
Command | Description |
| Reverse order |
| Recursive list |
| Show all (including hidden) |
| Sort by last modified |
| Sort by file size |
| Long listing format |
| One file per line |
| Comma-separated output |
| Quoted output |
System Information Commands
Command | Description |
| Shows the name of the system host. |
| Displays the id of the host of the system. |
| This command is used to install and add new packages. |
| This command is used to show the current date and time. |
| Shows the calendar of the current month. |
| This command displays the name with which you are logged in. |
| This command is used to find the location of the source/binary file of a command and manuals sections for a specified file in Linux System. This command is similar to the find command but this command is faster as it produces more accurate results by taking less time compared to the find command. There are again a number of options available. |
File Permission Commands
Command | Description |
| read permission |
| write permission |
| execute permission |
| no permission |
| Assign full(read, write, and execute) permission to everyone |
| Assign full permission to the directory and all sub-directories |
| Assign full permission to the owner, and read and write permission to the group and others |
| Remove the execution permission of any file |
| Change the ownership of a file |
| Change the owner and group ownership of a file |
| Change the owner and group ownership of the directory and all sub-directories |
Disk Management Commands
Command | Description |
| List all disk partitions |
| Create a new partition on /dev/sda device |
| Format the partition named /dev/sda1 |
| Check and repair a filesystem for any error |
| Mount any partition to any directory |
| Display free space of mounted file system |
| Display free inodes on the filesystem |
| Display the size of your current directory |
| Display information about block devices |
| Display all USB devices |
| Perform a read speed test on disk /dev/sda |
| Test for unreadable blocks on disk /dev/sda |
| Display and manage the top processes |
| Interactive process viewer (top alternative) |
| Display processor-related statistics |
| Display virtual memory statistics |
| Display I/O statistics |
| Display the last 100 Syslog messages (Use /var/log/syslog for Debian-based systems.) |
| Capture and display all packets on interface eth0 |
| Monitor all traffic on port 80 ( HTTP ) |
| List all open files on the system |
| List files opened by the user |
| Display free and used memory ( -h for human readable, -m for MB, -g for GB.) |
| Execute "df -h", showing periodic updates |
User Management Commands
Command | Description |
| To add a new user |
| To change the password of a user |
| To remove a newly created user |
| To add a user to a group |
| To remove a user from a group |
| Shows information of all the users logged in |
| Gives information about a particular user |
File and Directory Compression Commands
Command | Description |
| This command is used to compress a file with gzip compression. |
| This command is used to unzip a file that has gzip compression. |
| This command is used to create an uncompressed tar archive. |
| This command is used to create a tar archive with gzip compression. |
| This command is used to extract the contents of any type of tar archive. |
| Compress a file in the Tar archive |
| Uncompress a Tar file |
| List the content of the Tar file |
| Untar a single file from Tar file |
| Add a file to the Tar file |
| Compress a single file to a zip |
| Compress multiple files to a zip |
| Add a file to a zip file |
| Delete a file from a zip file |
| Display the content of the zip archive file |
| Unzip a file |
| Unzip a file to a specific directory |
Networking command
Command | Description |
| login into a remote Linux machine using SSH |
| To ping and Analyze network and host connections |
| Display files in the current directory of a remote computer |
| change the directory to “dirname” on a remote computer |
| upload ‘file’ from a local to a remote computer |
| Download the ‘file’ from the remote to the local computer |
| Logout |
Process command
Command | Description |
| To send a process to the background |
| To run a stopped process in the foreground |
| Details on all Active Processes |
| Give the status of processes running for a user |
| Gives the status of a particular process |
| Gives the Process ID (PID) of a process |
| Kills a process |
| Starts a process with a given priority |
| Changes the priority of an already running process |
| Gives free hard disk space on your system |
| Gives free RAM on your system |
Git & Github Cheat Sheet
Git configuration
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"
Set the default editor:
git config --global core.editor Vim
Check the setting:
git config -listGit alias
Set up an alias for each command:git config --global alias.co checkoutgit config --global alias.br branchgit config --global alias.ci commitgit config --global alias.st status
Starting a project
Git init
Create a local repository:
git initGit clone
Make a local copy of the server repository.
git clone
Local changes
Git add
Add a file to the staging (Index) area:
git add Filename
Add all files of a repo to the staging (Index) area:
git add .Git commit
Record or snapshot the file permanently in the version history with a message.
git commit -m " Commit Message"
Track changes
Git diff
Track the changes that have not been staged:git diff
Track the changes that have been staged but not committed:
git diff --staged
Track the changes after committing a file:
git diff HEAD
Track the changes between two commits:
git diff <commit hash 1> <commit hash 2>Git status
Display the state of the working directory and the staging area.
git statusGit show Shows objects:
git show
Commit History
Git log
Display the most recent commits and the status of the head:
git log
Display the output as one commit per line:
git log -oneline
Displays the files that have been modified:
git log -stat
Display the modified files with the location:
git log -pGit blame
Display the modification on each line of a file:
git blame <file name>
Ignoring files
.gitignore
Specify intentionally untracked files that Git should ignore.Create .gitignore:
touch .gitignoreList the ignored files:
git ls-files -i --exclude-standard
Branching
Git branch
Create branch:
git branchList Branch:
git branch --listDelete a Branch:
git branch -dDelete a remote Branch:
git push origin -deleteRename Branch:
git branch -mGit checkout
Switch between branches in a repository.
Switch to a particular branch:
git checkout branch_name
Create a new branch and switch to it:
git checkout -b branch_nameGit stash
Switch branches without committing to the current branch. Stash current work:
git stash
Saving stashes with a message:
git stash save ""
Check the stored stashes:
git stash list
Re-apply the changes that you just stashed:
git stash apply
Track the stashes and their changes:
git stash show
Re-apply the previous commits:
git stash pop
Delete a most recent stash from the queue:
git stash drop
Delete all the available stashes at once:
git stash clear
Stash work on a separate branch:
git stash branchGit cherry pic
Apply the changes introduced by some existing commits:
git cherry-pick commit_id
Merging
Git merge
Merge the branches:
git merge
Merge the specified commit to the currently active branch:
git mergeGit rebase
Apply a sequence of commits from distinct branches into a final commit.
git rebase
Continue the rebasing process:
git rebase -continueAbort the rebasing process:
git rebase --skipGit interactive rebase
Allow various operations like edit, rewrite, reorder, and more on existing commits.
git rebase -i
Remote
Git remote
Check the configuration of the remote server:
git remote -v
Add a remote for the repository:
git remote addFetch the data from the remote server:
git fetch
Remove a remote connection from the repository:
git remote rm
Rename remote server:
git remote rename
Show additional information about a particular remote:
git remote show
Change remote:
git remote set-urlGit origin master
Push data to the remote server:
git push origin masterPull data from the remote server:
git pull origin master
Push
Git push
Transfer the commits from your local repository to a remote server.Push data to the remote server:
git push origin masterForce push data:
git push -f
Delete a remote branch by push command:
git push origin --delete branch_name
Pull
Git pull
Pull the data from the server:
git pull origin master
Pull a remote branch:
git pullGit fetch
Download branches and tags from one or more repositories.Fetch the remote repository:
git fetch <repository Url>Fetch a specific branch:
git fetch
Fetch all the branches simultaneously:
git fetch -all
Synchronize the local repository:
git fetch origin
Undo changes
Git revert
Undo the changes:
git revert
Revert a particular commit:
git revert <commit hash>Git reset
Reset the changes:git reset -hardgit reset -softgit reset --mixed
Removing files
- Git rm
Remove the files from the working tree and from the index:
git rm <file Name>
Remove files from Git But keep the files in your local repository:
git rm --cached
Thank you for reading!!!
~Bhaarat




