Skip to main content

Command Palette

Search for a command to run...

Linux & Git-GitHub Cheat Sheet

Published
•4 min read•View as Markdown

Linux Cheat Sheet :

CommandDescriptionExample
lsLists files and directories in the current directory.ls -l (detailed listing)
mkdirCreates a new directory.mkdir newdir
touchCreates an empty file or updates the timestamp of an existing file.touch file.txt
echoDisplays text or variables, or writes to a file.echo "Hello" > file.txt
catDisplays the contents of a file.cat file.txt
vimOpens a file in the Vim text editor.vim file.txt
nanoOpens a file in the Nano text editor (user-friendly alternative to Vim).nano file.txt
rmRemoves a file.rm file.txt
rm -fForcibly removes a file without confirmation.rm -f file.txt
rm -rfRecursively and forcibly removes directories and their contents.rm -rf folder
unameDisplays system information.uname -a (detailed system info)
whoamiDisplays the current logged-in user.whoami
uptimeShows how long the system has been running and system load averages.uptime
dfShows disk space usage of the file systems.df -h (human-readable format)
duShows disk usage of files and directories.du -sh folder (summary for folder)
useraddAdds a new user to the system.sudo useradd newuser
groupaddAdds a new group to the system.sudo groupadd newgroup
userdelDeletes a user from the system.sudo userdel olduser
groupdelDeletes a group from the system.sudo groupdel oldgroup
chmodChanges file or directory permissions.chmod 755 file.txt (sets read/write/execute permissions)
chownChanges the owner of a file or directory.sudo chown user:group file.txt
passwdChanges a user's password.passwd
cpCopies files or directories.cp file1.txt file2.txt
mvMoves or renames files or directories.mv file1.txt newfolder/
dateDisplays or sets the system date and time.date
topShows real-time system processes and resource usage.top
psDisplays a snapshot of currently running processes.ps aux (detailed list of processes)
grepSearches for patterns in files or output.grep "text" file.txt
wcCounts lines, words, and characters in a file.wc -l file.txt (counts lines)
watchRuns a command repeatedly, showing its output in real-time.watch df -h (shows disk usage every 2 seconds)
historyShows the command history of the current session.history
manDisplays the manual for a command.man ls
whichShows the location of a command in the system's PATH.which ls

Git Cheat Sheet :

Git CommandDescriptionExample
git initInitializes a new Git repository in the current directory.git init
git addAdds changes from the working directory to the staging area.git add file.txt
git commitRecords the staged changes as a commit.git commit -m "Initial commit"
git statusDisplays the status of the working directory and the staging area.git status
git logShows the commit history of the repository.git log
git pushPushes local commits to the remote repository.git push origin main
git pullFetches and merges changes from the remote repository into the current branch.git pull origin main
git remote addAdds a new remote repository to track.git remote add origin <repository-url>
git mergeMerges changes from one branch into another.git merge feature-branch
git rebaseReapplies commits from one branch onto another branch.git rebase main
git resetResets the current branch to a specific commit, modifying the staging area or working directory.git reset --hard HEAD~1
git revertCreates a new commit that reverses the changes of a previous commit.git revert <commit-hash>
git branchLists, creates, or deletes branches.git branch
git checkoutSwitches to another branch or restores files to a previous commit.git checkout feature-branch
git stashTemporarily saves changes in the working directory that are not yet ready to commit.git stash
git cloneCreates a copy of an existing repository in a new directory.git clone <repository-url>

Happy Learning:)