Cheat Sheet for Linux & Git
Linux Commands
File Commands
Command | Description |
pwd | Displays the present working directory |
ls | Lists all files and directories in the current directory |
ls -a | Displays all files and directories, including hidden ones |
ls -l | Displays detailed information about files and directories |
mkdir <directory_name> | Creates a new directory |
mkdir -p A/B/C/D | Creates 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 |
history | Displays a list of previously executed commands |
grep <search_string> <file_name> | Searches for a specific string in a file |
head | Displays the first few lines of a file |
tail | Displays the last few lines of a file |
df -H | Shows disk usage information |
File Permissions
Permission | Description |
chmod <permission> <file_name> | Changes the permissions of a file or directory |
0 | No permissions |
4 | Read permission |
2 | Write permission |
1 | Execute permission |
r | Read permission |
w | Write permission |
x | Execute permission |
u | User |
g | Group |
o | Other |
Access Control List (ACL)
Command | Description |
setfacl | Sets ACL permissions |
getfacl | Displays ACL permissions |
User Management
Command | Description |
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
Command | Description |
git init | Initializes 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 status | Displays the status of the Git repository |
Git Branching
Command | Description |
git branch | Lists 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
Command | Description |
git remote -v | Lists all remote repositories |
git remote add origin <remote_git_url> | Adds a remote repository |
git remote remove origin | Removes 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 fetch | Fetches all remote branches |
git log | Displays commit history |
Git Configuration
Command | Description |
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 |
Command | Description |
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 stash | Temporarily saves modified and staged changes. |
git stash list | Displays a list of stashed changes. |
git stash pop | Applies the topmost stashed change to the working directory and removes it from the stash. |