Linux Cheat Sheet

Rajat Chauhan is a skilled Devops Engineer, having experience in automating, configuring, deploying releasing and monitoring the applications on cloud environment.
• Good experience in areas of DevOps, CI/CD Pipeline, Build and Release management, Hashicorp Terraform, Containerization, AWS, and Linux/Unix Administration. • As a DevOps Engineer, my objective is to strengthen the company’s applications and system features, configure servers and maintain networks to reinforce the company’s technical performance. • Ensure that environment is performing at its optimum level, manage system backups and provide infrastructure support. • Experience working on various DevOps technologies/ tools like GIT, GitHub Actions, Gitlab, Terraform, Ansible, Docker, Kubernetes, Helm, Jenkins, Prometheus and Grafana, and AWS EKS, DevOps, Jenkins. • Positive attitude, strong work ethic, and ability to work in a highly collaborative team environment. • Self-starter, Fast learner, and a Team player with strong interpersonal skills • Developed shell scripts (Bash) for automating day-to-day maintenance tasks on top of that have good python scripting skills. • Proficient in communication and project management with good experience in resolving issues.
Basic Commands
Navigation
pwd: Print the current working directory.cd [dir]: Change directory to[dir]. Usecd ..to go up one level.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.
File Operations
touch [file]: Create an empty file or update the timestamp of the file.cp [source] [destination]: Copy file or directory.cp -r [source] [destination]: Copy directories recursively.
mv [source] [destination]: Move or rename file or directory.rm [file]: Remove file.rm -r [dir]: Remove directory and its contents recursively.rm -i [file]: Remove with a prompt before every removal.
File Viewing
cat [file]: Concatenate and display file content.less [file]: View file content one screen at a time.more [file]: View file content, similar toless.head [file]: Display the first 10 lines of a file.head -n [num] [file]: Display the first[num]lines of a file.
tail [file]: Display the last 10 lines of a file.tail -n [num] [file]: Display the last[num]lines of a file.tail -f [file]: Follow the file content as it grows.
File Permissions
chmod [permissions] [file]: Change the file permissions.chmod 755 [file]: Set permissions to rwxr-xr-x.chmod u+x [file]: Add execute permission for the owner.
chown [owner]:[group] [file]: Change file owner and group.chgrp [group] [file]: Change group ownership.
File Permissions Symbols
r: Read permission.w: Write permission.x: Execute permission.-: No permission.
Access Control Lists (ACL)
getfacl [file]: Get 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.
Process Management
ps: Display current processes.ps aux: Display detailed information about all running processes.
top: Display dynamic real-time view of running processes.htop: Enhanced version oftop(needs to be installed).kill [pid]: Terminate process with process ID[pid].kill -9 [pid]: Forcefully terminate process with process ID[pid].
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.
Disk Usage
df: Report file system disk space usage.df -h: Human-readable format.
du [file/dir]: Estimate file space usage.du -sh [file/dir]: Display summary in human-readable format.
Networking
ping [host]: Check the network connection to a server.ifconfig: Configure network interfaces (deprecated; useip).ip addr: Show IP addresses and network interfaces.netstat: Network statistics.netstat -tuln: List all listening ports.
wget [url]: Download files from the web.curl [url]: Transfer data from or to a server.
Searching
grep [pattern] [file]: Search for a pattern in a file.grep -r [pattern] [dir]: Search recursively in a directory.grep -i [pattern] [file]: Case-insensitive search.
find [dir] -name [pattern]: Find files by name.locate [name]: Find files by name (uses a database, needs to be updated withupdatedb).
Archiving and Compression
tar -cvf [archive.tar] [file/dir]: Create a tar archive.tar -xvf [archive.tar]: Extract a tar archive.tar -czvf [archive.tar.gz] [file/dir]: Create a compressed tar archive with gzip.tar -xzvf [archive.tar.gz]: Extract a compressed tar archive with gzip.zip [archive.zip] [file/dir]: Create a zip archive.unzip [archive.zip]: Extract a zip archive.
Package Management
Debian/Ubuntu:
apt update: Update package lists.apt upgrade: Upgrade installed packages.apt install [package]: Install a package.apt remove [package]: Remove a package.apt autoremove: Remove unnecessary packages.
Red Hat/CentOS:
yum update: Update package lists and upgrade packages.yum install [package]: Install a package.yum remove [package]: Remove a package.yum autoremove: Remove unnecessary packages.
Service Management
Systemd:
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 user password.deluser [username]: Remove a user.usermod -aG [group] [username]: Add a user to a group.groups [username]: List the groups a user is in.
Shell Scripting
Basic Structure:
#!/bin/bash echo "Hello, World!"Variables:
NAME="John" echo "Hello, $NAME"Conditional Statements:
if [ condition ]; then # Commands elif [ condition ]; then # Commands else # Commands fiLoops:
for i in {1..5}; do echo "Iteration $i" done while [ condition ]; do # Commands done
Additional Useful Commands
echo [text]: Display 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.uname -a: Show system information.history: Show command history.






