Cheat Sheet for Linux & Git

Linux Commands

File Commands

CommandDescription
pwdDisplays the present working directory
lsLists all files and directories in the current directory
ls -aDisplays all files and directories, including hidden ones
ls -lDisplays detailed information about files and directories
mkdir <directory_name>Creates a new directory
mkdir -p A/B/C/DCreates a nested directory structure
rmdir <directory_name>Removes an empty directory
rm -rf <directory_name>Removes a directory and all its contents
rm <file_name>Removes a file
cd <path>Changes the working directory
touch <file_name>Creates an empty file
cp <source_path> <destination_path>Copies a file
mv <source_path> <destination_path>Moves a file
echo <message> > <file_name>Writes text to a file
cat <file_name>Displays the contents of a file
historyDisplays a list of previously executed commands
grep <search_string> <file_name>Searches for a specific string in a file
headDisplays the first few lines of a file
tailDisplays the last few lines of a file
df -HShows disk usage information

File Permissions

PermissionDescription
chmod <permission> <file_name>Changes the permissions of a file or directory
0No permissions
4Read permission
2Write permission
1Execute permission
rRead permission
wWrite permission
xExecute permission
uUser
gGroup
oOther

Access Control List (ACL)

CommandDescription
setfaclSets ACL permissions
getfaclDisplays ACL permissions

User Management

CommandDescription
sudo useradd <user_name>Creates a new user
sudo passwd <user_name>Sets a password for a user
sudo usermod <user_name>Modifies a user's information
sudo userdel <user_name>Deletes a user
sudo groupadd <group_name>Creates a new group

Git Commands

CommandDescription
git initInitializes a new Git repository
git clone <repository_url>Clones an existing Git repository
git add <file_name>Adds a file to the staging area
git add .Stages all files in the current directory
git commit -m <message>Commits the staged changes with a message
git statusDisplays the status of the Git repository

Git Branching

CommandDescription
git branchLists all branches
git branch <branch_name>Creates a new branch
git checkout <branch_name>Switches to a specific branch
git checkout -b <branch_name>Creates and switches to a new branch
git checkout -d <branch_name>Deletes a branc

Remote Origin

CommandDescription
git remote -vLists all remote repositories
git remote add origin <remote_git_url>Adds a remote repository
git remote remove originRemoves a remote repository
git push origin <branch_name>Pushes local changes to a remote repository
git pull origin <branch_name>Pulls remote changes to the local repository
git fetchFetches all remote branches
git logDisplays commit history

Git Configuration

CommandDescription
git config --global user.name <your_username>Sets the author name for commits
git config --global user.email <your_email>Sets the author email for commits
CommandDescription
git merge <branch_name>Merges the specified branch into the current branch.
git cherry-pick <commit_id>Selectively merges a specific commit from another branch into the current branch.
git revert <commit_id>Undoes a specific commit without affecting subsequent commits.
git reset <commit_id>Moves the HEAD pointer back to the specified commit, discarding any changes made after that commit.
git rebase <other_branch_name>Rewrites the history of the current branch by applying its commits on top of the specified branch's history.
git stashTemporarily saves modified and staged changes.
git stash listDisplays a list of stashed changes.
git stash popApplies the topmost stashed change to the working directory and removes it from the stash.