Day 14: Essential Linux and Git-GitHub Cheat Sheet

💼 Senior Software Engineer

File and Directory Management🗂️
ls: List directory contents.ls -l: List in long format.ls -a: List all files including hidden files (those starting with a dot).ls -lh: Long format with human-readable file sizes
cd: Change the current directory.- Change the directory to
[dir]. Usecd ..to go up one level.
- Change the directory to
pwd: Print the current working directory.mkdir: Create a new directory.mkdir new_folderrmdir: Remove an empty directory.rmdir old_folderrm: Remove files or directories.rm -r [dir]: Remove the directory and its contents recursively.rm -i [file]: Remove with a prompt before every removal.
File Permissions and Ownership🛡️
chmod: Change file permissions.Example:
chmod 755script.shchmod 755 [file_name]: Set permissions to rwxr-xr-x.chmod u+x [file_name]: Add execute permission for the owner.
chown: Change file owner and group.- Example:
chown user:group file.txt
- Example:
chgrp: Change group ownership.- Example:
chgrp groupname file.txt
- Example:
File Permissions Symbols🔑
r: Read permission.w: Write permission.x: Execute permission.-: No permission.
Viewing and Editing Files📖
cat: Concatenate and display file contents.- Example:
cat file.txt
- Example:
less: View file contents one screen at a time.- Example:
less file.txt
- Example:
nano: Simple text editor.- Example:
nano file.txt
- Example:
viorvim: Advanced text editor.- Example:
vim file.txt
- Example:
Process Management⏳
ps: Display current processes.- Example:
ps aux- Display detailed information about all running processes.
- Example:
top: Display and manage processes in real-time.- Example:
top
- Example:
htop: Enhanced version oftop(needs to be installed).kill: Terminate a process.- Example:
kill 1234(terminate the process with PID 1234)
- Example:
killall [process_name]: Terminate all processes with the specified name.bg: Resume a suspended job in the background.fg: Bring a background job to the foreground.jobs: List all background jobs.systemctl: Manage system services.- Example:
systemctl start nginx(start nginx service),systemctl status nginx(check status of nginx service)
- Example:
Networking🌐
ifconfig: Display or configure network interfaces.- Example:
ifconfig eth0
- Example:
ping [host]: Check the network connection to a server.- Example:
pinggoogle.com
- Example:
netstat: Network statistics.- Example:
netstat -tuln(List all listening ports.)
- Example:
wget [url]: Download files from the web.curl [url]: Transfer data from or to a server.ip addr: Show IP addresses and network interfaces.
Disk Usage💾
df: Display disk space usage.- Example:
df -hhuman-readable format.
- Example:
du: Estimate file space usage.- Example:
du -sh [file/dir]: Display summary in human-readable format.
- Example:
Archive and Compression📦
tar: Archive files.- Example:
tar -cvf archive.tar folder/(create),tar -xvf archive.tar(extract)
- Example:
gzip: Compress files.- Example:
gzip file.txt
- Example:
gunzip: Decompress files.- Example:
gunzip file.txt.gz
- Example:
zip [archive.zip][file/dir]: Create a zip file archive.unzip [archive.zip]: Extract zip file archive.
Access Control Lists (ACL)🔐
getfacl [file]: Get the ACL of a file.setfacl -m u:[user]:[permissions] [file]: Set ACL for a user.setfacl -m g:[group]:[permissions] [file]: Set ACL for a group.setfacl -x u:[user] [file]: Remove ACL for a user.
Searching🕵🏻
grep [pattern] [file]: Search for a pattern in a file.grep -r [pattern] [dir]: Recursively Search in a directory.grep -i [pattern] [file]: Search Case-insensitive file name .find [dir] -name [pattern]: Find files by name.locate [name]: Find files by name (uses a database, needs to be updated withupdatedb).
Package Management🛒
apt update: Update package lists but it does not install or upgrade any packages.apt upgrade: Installed or upgraded packages.apt install [package]: Install a package.apt remove [package]: Remove a package.apt autoremove: Remove unnecessary packages.
Service Management🛠️
systemctl start [service]: Start a service.systemctl stop [service]: Stop a service.systemctl restart [service]: Restart a service.systemctl status [service]: Check the status of a service.systemctl enable [service]: Enable a service to start on boot.systemctl disable [service]: Disable a service from starting on boot.
User Management👨🏻💻
adduser [username]: Add a new user.passwd [username]: Change the user password.deluser [username]: Remove a user.usermod -aG [group] [username]: Add a user to a group.groups [username]: Display list the groups a user is in.
Shell Scripting📜
Structure:
#!/bin/bash
echo "Hello"
Variables Use:
#!/bin/bash
NAME="Ketan"
echo "Hello, $NAME"
Conditional Statements- If & else:
if [ condition ]; then
# Commands
elif [ condition ]; then
# Commands
else
# Commands
fi
Loops- For and While:
for i in {1..5}; do
echo "Iteration $i"
done
while [ condition ]; do
# Commands
done
Other Commands 📑
echo [text]: Display the text.date: Display or set the system date and time.uptime: Show how long the system has been running.who: Show who is logged on.history: Show command history.

Configuration🔧
git config: Set configuration values.Example:
git config --globaluser.name"Your Name",git config --globaluser.email"you@example.com"
Repository Management📂
git init: Initialize a new Git repository.git clone: Clone a repository into a new directory.- Example:
git clonehttps://github.com/user/repo.git
- Example:
Basic Snapshotting⚙️
git add: It will move all the files to the staging.- Example:
git add file.txt
- Example:
git commit: It is used to create a new commit with a specific commit message- Example:
git commit -m "Initial commit"
- Example:
git status: Show the working tree status.git log: It will display a list of commits.git diff: Show changes between two commit IDs and working tree, etc.
Branching and Merging🎋
git branch: List, create, or delete branches.- Example:
git branch(list),git branch new-branch(create),git branch -d old-branch(delete)
- Example:
git checkout: Switch branches or restore working tree files.- Example:
git checkout new-branch(switch),git checkout -b new-branch(create and switch)
- Example:
git merge: Join two or more development histories together.- Example:
git merge new-branch
- Example:
Remote Repositories🍃
git remote: Manage a set of tracked repositories.- Example:
git remote -v(list),git remote add originhttps://github.com/user/repo.git(add remote)
- Example:
git fetch: Download objects and refs from another repository.- Example:
git fetch origin
- Example:
git pull: It will pull the changes from the remote repository to the local.- Example:
git pull origin main
- Example:
git push: Update the remote references along with their associated objects.- Example:
git push origin main
- Example:
Rewriting History⌛
git reset: Reset current HEAD to the specified state.Example:
git reset --hard HEAD~1(delete all commit)git reset --soft HEAD~1(remove from history but store in file system/staging area)
git revert: Create a new commit that undoes the changes by creating/adding new commits.- Example:
git revert HEAD
- Example:
git rebase: Reapply commits on top of another base tip and it will maintain in a linear format.- Example:
git rebase main
- Example:
Additional Tips👀
.gitignore: Text file used in Git repositories to specify which files and directories should be ignored and not tracked by Git.- Example: Add
node_modules/to.gitignoreto ignore all files in thenode_modulesdirectory.
- Example: Add
Conclusion🎯
It provides quick and concise information to help manage files, processes, permissions, and version control efficiently, thereby streamlining workflows and improving the productivity of DevOps Engineers.




