Cheat Sheet for Linux & Git

Cheat Sheet for Linux & Git

Linux

It provides services for applications and manages computer hardware. It's a platform to run desktops, embedded systems, and servers. It is made up of several different components working together to form an Operating System which is organized into layers. Each layer interacts with the other to provide its functionality.

There are over a thousand Linux commands and it would be hard to remember them all. You can always search for them online and as you use them you will become familiar with them. Below are some of the common commands that a DevOps Engineer will come across.

CommandsDescription
lsLists files and directories in the current directory
pwdPrints the current working directory
cdChanges the current working directory
mkdirCreates a new directory
mvMoves or renames files or directories
rmRemoves files or directories
touchCreates an empty file
catConcatenates and displays files
clearTo clear the terminal screen of all previous output
echoTo print a message or value to the terminal
whoamiTo display the username of the current user
tarCompresses and decompresses files and directories
grepTo search for a specified pattern in one or more text files
headTo display the first few lines of a text file
tailTo display the last few lines of a text file
diffTo compare the contents of two text files and display the difference between them.
sortTo sort the lines of a text file
chmodChanges the permissions of a file or directory
chownChanges the owner of a file or directory
sudoRuns a command with administrative privileges
useraddTo create a new user account
usermodTo modify an existing user account
passwdTo set or change the password of a user account
exitTo close a terminal session or shell
vimThe text editor in Linux, that is used to create and edit text files
awkTool in Linux that is used to manipulate and process text files.

If you would like to see the above commands used in action, see the below blogs on Linux:

  1. Basic Linux Commands

  2. Basic Linux Shell Scripting for DevOps Engineers

  3. Advanced Linux Shell Scripting for DevOps Engineers with User Management

  4. File Permissions & Access Control Lists

  5. Understanding Package Manager and Systemctl - Linux


Git

As described by [git-scm.com] - "Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency."

It allows developers to track changes to their code over time and collaborate with other developers on the same project by providing features for sharing and merging code changes. When multiple developers are working on the same project, each developer can create a separate local repository and make changes without affecting the main codebase. Git offers tools to integrate these independent changes into a unified codebase and resolve any conflicts that may arise.

There are many Git Commands that are out there and it would be hard to remember them all. You can always search for them online and as you use them you will become familiar with them. Below are some of the common commands that a DevOps Engineer will come across.

CommandsDescription
git cloneCreates a copy of a remote repository on the local machine.
git statusShows the current state of the repository, including any uncommitted changes
git addAdds a file or directory to the staging area
git commitCommits the staged changes with a commit message
git pushPushes local changes to a remote repository
git remote add originused to add a remote repository to your local Git repository
git push origin mainUsed to push the commits made in the local main branch to the remote repository called the origin
git initInitializes a new Git repository in the current directory
git branchLists all branches in the repository
git config --global user.nameUsed to set your Git username. This username will be associated with the commits you make to your Git repositories
git config --global user.emailUsed to set your Git email address. This email address will be associated with the commits you make to your Git repositories
git config --listUsed to view the Git configuration settings for your local Git installation. These settings can include your username, email address, default text editor, and more
git log --onelineUsed to view the commit history of a Git repository in a simplified format. Each commit is displayed on a single line with the first few characters of its commit hash and its commit message
git revertReverts a commit by creating a new commit that undoes the changes in the specified commit
git resetRemoves a file from the staging area
git rebaseUsed to apply a sequence of commits from one branch to another branch. It rewrites the project history by applying the changes of the rebased branch on top of the target branch. This results in a cleaner and more linear history
git mergeMerges the specified branch into the current branch
git checkout -b <branch>Creates & switches to the "newly created" branch
git checkoutSwitches to a different branch
git stashUsed to temporarily save changes that are not yet ready to be committed, allowing you to switch branches or perform other actions without losing your work
git cherry-pickUsed to apply a specific commit from one branch to another. This command is useful when you want to apply changes made in a specific commit on one branch to another branch without merging the entire branch
git pullFetches and merges change from a remote repository into the local repository
git diffShows the changes between the working directory and the repository.

If you would like to see the above commands used in action, see the below blogs on Git:

  1. Basic Git & GitHub for DevOps Engineers

  2. Deep Dive in Git & GitHub for DevOps Engineers

  3. Advance Git & GitHub for DevOps Engineers: Part-1

  4. Advance Git & GitHub for DevOps Engineers: Part-2


I appreciate your busy time reading this short blog. As I continue with my journey to learn and acquire the skill set of a DevOps Engineer, I will share what I learn. Thank you.

Happy Learning!


Sam Samarullah

LinkedIn

Previous Blog

#git #github #linux #linux commands #devops #devopstools