Day 14 Task: Create a Linux & Git-GitHub Cheat Sheet

Linux Command Cheat Sheet

Basic File and Directory Commands

CommandDescriptionExample
pwdPrints the current working directorypwd
lsLists files and directoriesls -l (detailed list)
cdChanges the current directorycd /home/user/
mkdirCreates a new directorymkdir new_folder
rmdirRemoves an empty directoryrmdir old_folder
rmRemoves files or directoriesrm file.txt (file), rm -r folder/ (directory)
cpCopies files or directoriescp file.txt /path/to/destination/
mvMoves or renames files or directoriesmv file.txt new_name.txt
touchCreates an empty filetouch file.txt

File Viewing and Editing

CommandDescriptionExample
catDisplays file contentscat file.txt
nanoOpens a file in Nano editornano file.txt
lessViews file content, one screen at a timeless file.txt
headDisplays the first 10 lines of a filehead file.txt
tailDisplays the last 10 lines of a filetail file.txt
tail -fMonitors a file for real-time updatestail -f /var/log/syslog
grepSearches text in filesgrep 'error' /var/log/syslog

File Permissions and Ownership

CommandDescriptionExample
chmodChanges file permissionschmod 755 script.sh
chownChanges file ownershipchown user:group file.txt
chgrpChanges group ownershipchgrp group file.txt
ls -lLists file permissions and ownershipls -l

Process Management

CommandDescriptionExample
psLists running processesps aux
topDisplays running processes and system infotop
htopInteractive process viewerhtop
killTerminates a processkill 1234 (kill process with PID 1234)
killallTerminates all processes by namekillall firefox
bgResumes a suspended job in the backgroundbg %1
fgBrings a background job to the foregroundfg %1
jobsLists all background jobsjobs
niceStarts a process with modified scheduling prioritynice -n 10 command
reniceChanges priority of running processesrenice +10 1234 (change priority of PID 1234)

System Information and Monitoring

CommandDescriptionExample
uname -aShows system informationuname -a
uptimeDisplays system uptime and load averageuptime
dfShows disk space usagedf -h
duShows disk usage of files/directoriesdu -sh /path/to/folder/
freeDisplays memory usagefree -m
dmesgKernel ring buffer logsdmesg
lastDisplays the last logged-in userslast
whoShows who is currently logged inwho
iostatReports CPU and I/O statisticsiostat
vmstatReports virtual memory statisticsvmstat 1 5 (run 5 times with 1 sec interval)

User Management

CommandDescriptionExample
whoamiShows the current logged-in userwhoami
useraddAdds a new usersudo useradd new_user
passwdChanges user passwordpasswd username
usermodModifies a user accountsudo usermod -aG sudo username
groupaddAdds a new groupsudo groupadd dev_group
groupsDisplays user group membershipsgroups username
deluserDeletes a usersudo deluser username
sudoRuns a command with superuser privilegessudo apt update

Networking Commands

CommandDescriptionExample
pingChecks network connectivityping google.com
ifconfigDisplays network interfaces (deprecated)ifconfig
ip addrDisplays network interfaces (new)ip addr
netstatShows network connections and portsnetstat -tuln
sshConnects to a remote server via SSHssh user@host
scpSecurely copies files between systemsscp file.txt user@remote:/path/to/destination
tracerouteTraces the route to a network hosttraceroute google.com
wgetDownloads files from the webwget http://example.com/file.zip
curlTransfers data from a URLcurl http://example.com

Package Management

CommandDescriptionExample
apt-get installInstalls a package (Debian/Ubuntu)sudo apt-get install vim
yum installInstalls a package (RHEL/CentOS)sudo yum install nano
dnf installInstalls a package (Fedora)sudo dnf install httpd
apt-get updateUpdates package lists (Debian/Ubuntu)sudo apt-get update
yum updateUpdates all packages (RHEL/CentOS)sudo yum update
apt-get upgradeUpgrades installed packages (Debian/Ubuntu)sudo apt-get upgrade
apt-get removeRemoves a package (Debian/Ubuntu)sudo apt-get remove package_name
dpkg -iInstalls a package manually (Debian)sudo dpkg -i package.deb

System and Service Management

CommandDescriptionExample
systemctlControls system services (systemd)systemctl status apache2
serviceManages system services (older systems)service apache2 status
rebootRestarts the systemsudo reboot
shutdownShuts down the systemsudo shutdown now
crontab -eEdits cron jobs for scheduled taskscrontab -e
journalctlViews logs generated by systemd servicesjournalctl -xe

Git & GitHub Command Cheat Sheet

Repository Setup

CommandDescriptionExample
git initInitializes a new Git repositorygit init
git cloneClones an existing repository to your local machinegit clone https://github.com/user/repo.git
git remote addAdds a remote repositorygit remote add origin https://github.com/user/repo.git

Working with Changes

CommandDescriptionExample
git statusShows the status of the working directory and staging areagit status
git addAdds changes to the staging areagit add .
git commitRecords changes with a commit messagegit commit -m "Initial commit"
git diffShows changes between commits or working directorygit diff HEAD
git resetResets changes in working directory or commit historygit reset --hard HEAD~1
git revertReverts changes by creating a new commitgit revert HEAD
git rmRemoves a file from the working directory and Git indexgit rm file.txt

Branching & Merging

CommandDescriptionExample
git branchLists, creates, renames, or deletes branchesgit branch dev
git checkoutSwitches between branchesgit checkout dev
git mergeMerges branches togethergit merge feature-branch
git rebaseMoves or reapplies commits from one branch onto anothergit rebase main
git cherry-pickApplies changes from specific commitsgit cherry-pick abc123
git log --graphShows branch history in a graph formatgit log --graph --all

Remote Repositories

CommandDescriptionExample
git pullFetches changes from the remote and merges themgit pull origin main
git fetchFetches changes from a remote without merginggit fetch origin
git pushPushes local commits to the remote repositorygit push origin main
git remote -vShows remote repository URLgit remote -v

Stashing & Tagging

CommandDescriptionExample
git stashTemporarily saves changes in a stashgit stash
git stash popApplies stashed changes and removes the stashgit stash pop
git tagLists, creates, or deletes tagsgit tag v1.0
git tag -dDeletes a taggit tag -d v1.0
git showDisplays information about a tag or commitgit show v1.0

Configuration & Logs

CommandDescriptionExample
git config --globalSets global configuration valuesgit config --global user.name "Your Name"
git logDisplays the commit historygit log --oneline --graph --decorate
git reflogShows the reference logsgit reflog
git blameShows who last modified each line in a filegit blame file.txt
git bisectHelps to find the commit that introduced a buggit bisect start

GitHub-Specific Commands

CommandDescriptionExample
gh repo createCreates a new repository on GitHubgh repo create my-repo --public
gh issue createCreates a new issue on GitHubgh issue create --title "New Issue"
gh pr createCreates a pull requestgh pr create --base main --head dev --title "New PR"
gh pr mergeMerges a pull requestgh pr merge 123
gh issue listLists open issues on GitHubgh issue list
gh repo cloneClones a GitHub repositorygh repo clone owner/repo

Archiving & Cleanup

CommandDescriptionExample
git archiveCreates a tar or zip archive of files in the repositorygit archive --format=zip HEAD > archive.zip
git gcCleans up unnecessary files and optimizes the repositorygit gc

This cheat sheet organizes the most common Git and GitHub commands into categories like