Linux Cheat Sheet
File and Directory Operations:
ls: List files and directories- Usage:
ls [options] [path]
- Usage:
pwd: Print working directory- Usage:
pwd
- Usage:
cd: Change directory- Usage:
cd [directory]
- Usage:
mkdir: Make directory- Usage:
mkdir [directory]
- Usage:
rmdir: Remove directory- Usage:
rmdir [directory]
- Usage:
cp: Copy files and directories- Usage:
cp [options] source destination
- Usage:
mv: Move/rename files and directories- Usage:
mv [options] source destination
- Usage:
rm: Remove files and directories- Usage:
rm [options] file/directory
- Usage:
touch: Create an empty file- Usage:
touch [file]
- Usage:
cat: Concatenate and display file content- Usage:
cat [file]
- Usage:
Text editors:
nano: Usage:nano [file]vim: Usage:vim [file]
File Viewing and Manipulation:
head: Display the beginning of a file- Usage:
head [options] [file]
- Usage:
tail: Display the end of a file- Usage:
tail [options] [file]
- Usage:
less: View file content interactively- Usage:
less [file]
- Usage:
grep: Search for a pattern in files- Usage:
grep [options] 'pattern' [file(s)]
- Usage:
find: Search for files and directories- Usage:
find [path] [expression]
- Usage:
wc: Count lines, words, and characters in a file- Usage:
wc [options] [file]
- Usage:
sort: Sort lines in a file- Usage:
sort [options] [file]
- Usage:
cut: Remove sections from each line of a file- Usage:
cut [options] [file]
- Usage:
sed: Stream editor for text transformation- Usage:
sed [options] 'command' [file]
- Usage:
awk: Text processing tool- Usage:
awk 'pattern { action }' [file]
- Usage:
File Permissions:
chmod: Change file permissions- Usage:
chmod [options] mode [file(s)]
- Usage:
chown: Change file ownership- Usage:
chown [options] user[:group] [file(s)]
- Usage:
chgrp: Change group ownership- Usage:
chgrp [options] group [file(s)]
- Usage:
System Information and Monitoring:
uname: Print system information- Usage:
uname [options]
- Usage:
df: Disk space usage- Usage:
df [options]
- Usage:
du: Estimate file and directory space usage- Usage:
du [options] [directory]
- Usage:
free: Display memory usage- Usage:
free [options]
- Usage:
top: Monitor system processes- Usage:
top
- Usage:
ps: Display information about running processes- Usage:
ps [options]
- Usage:
htop: Interactive process viewer (if installed)- Usage:
htop
- Usage:
Package Management (Debian/Ubuntu):
apt-get: Command-line package handling utility- Usage:
apt-get [options] command
- Usage:
apt-cache: Query the package cache- Usage:
apt-cache [options] command
- Usage:
Package Management (Red Hat/Fedora):
yum: Package manager for RPM-based systems- Usage:
yum [options] [command]
- Usage:
dnf: Next-generation package manager (replacing yum)- Usage:
dnf [options] [command]
- Usage:
Network-related:
ping: Check connectivity to a host- Usage:
ping [options] host
- Usage:
Network interface configuration:
ifconfig: Usage:ifconfig [interface] [options]ip: Usage:ip [options] [address]
netstat: Network statistics- Usage:
netstat [options]
- Usage:
ssh: Secure shell client- Usage:
ssh [options] [user@]hostname
- Usage:
scp: Securely copy files between hosts- Usage:
scp [options] [source] [destination]
- Usage:
Download files from the web:
wget: Usage:wget [options] [URL]curl: Usage:curl [options] [URL]
DNS related queries:
nslookup: Usage:nslookup [options] domaindig: Usage:dig [options] domain
Compression and Archiving:
tar: Archive files- Usage:
tar [options] [archive] [file(s)]
- Usage:
gzip: Compress files- Usage:
gzip [options] [file]
- Usage:
gunzip: Decompress files- Usage:
gunzip [options] [file]
- Usage:
zip: Create ZIP files- Usage:
zip [options] [archive] [file(s)]
- Usage:
unzip: Extract ZIP files- Usage:
unzip [options] [archive.zip]
- Usage:
Process Management:
ps: Display information about running processes- Usage:
ps [options]
- Usage:
kill: Terminate processes- Usage:
kill [options] PID
- Usage:
Put a process in the background/foreground:
bg: Usage:bgfg: Usage:fg
System Shutdown/Reboot:
shutdown: Shutdown or reboot the system- Usage:
shutdown [options] [time] [message]
- Usage:
Miscellaneous:
date: Display or set the system date and time- Usage:
date [options] [format]
- Usage:
View command history:
history: Usage:history [options]
Create an alias for a command:
alias: Usage:alias [name]=[command]
Display manual pages for commands:
man: Usage:man [command]
Git Cheat Sheet
Configuration:
git config --globaluser.name"Your Name": Set your global username.git config --globaluser.email"youremail@example.com": Set your global email.git config --global core.editor "editor": Set your preferred text editor for commit messages.
Creating and Cloning Repositories:
git init: Initialize a new Git repository in the current directory.git clone <repository_url>: Clone an existing repository from a remote URL.
Basic Operations:
git add <file>: Add a file to the staging area to be included in the next commit.git add .: Add all modified files to the staging area.git commit -m "Commit message": Commit the staged changes with a descriptive message.git status: Show the status of files in the repository (modified, staged, etc.).git log: View commit history.git diff: Show the changes made to files but not yet staged.
Branching and Merging:
git branch: List all branches in the repository.git branch <branch_name>: Create a new branch.git checkout <branch_name>: Switch to an existing branch.git checkout -b <branch_name>: Create and switch to a new branch in one command.git merge <branch_name>: Merge the specified branch into the current branch.
Remote Repositories:
git remote: List remote repositories.git remote add <name> <url>: Add a remote repository with a custom name.git push <remote_name> <branch_name>: Push the local branch to the remote repository.git pull <remote_name> <branch_name>: Fetch and merge changes from a remote repository.
Undoing Changes:
git reset HEAD <file>: Unstage a file from the staging area.git reset --hard HEAD: Discard all changes and revert to the last commit.git revert <commit_hash>: Create a new commit that undoes the changes introduced by a specific commit.
Miscellaneous:
git rm <file>: Remove a file from the working directory and staging area.git stash: Temporarily save changes to a stash, allowing you to switch branches without committing.git remote -v: Display URLs of remote repositories.
Keep in mind that this is a concise cheat sheet covering some common Git commands. You can always find more information and options for each command in the Git documentation or by running git --help.




