Linux Cheat Sheet

blank
blank

Mastering Linux commands is essential for efficiently managing and automating tasks in a Linux environment. This cheat sheet provides a quick reference to commonly used commands, from basic file manipulations,networking, system monitoring and user management.

Whether you’re a beginner or an experienced user, these commands will help you work more effectively in the Linux shell.

File Management

CommandDescription
cat > file.txtCreate or overwrite contents of a file.
cat file.txtView file content.
cat >> file.txtAppend content to a file.
touch file.txtCreate an empty file.
touch .hiddenfileCreate a hidden file.
touch file1.txt file2.txtCreate multiple files.
cp <source> <destination>Copy files and directories.
mv <source> <destination>Move or rename files and directories.
rm <file.txt>Remove a file.
rm -rf <directory>Remove a directory and its contents recursively.
ln -s <source> <target>Create a symbolic link (soft link).
ln <source> <target>Create a hard link.
sort <options> <file>Sort file content.
cut -d: -f3 <file>Retrieve a specific column from a file using a delimiter.

Directory Management

CommandDescription
mkdir <directory>Create a new directory.
mkdir -p <path>Create a directory and any parent directories as needed.
ls <directory>List directory contents.
ls -alList all files, including hidden ones, in a long format.
pwdDisplay the current directory path.
cd <directory>Change the current directory.
cd ../Move one level up in the directory hierarchy.
rmdir <directory>Remove an empty directory.

Viewing and Editing Files

CommandDescription
less <file.txt>View file content page by page.
head -n10 <file.txt>View the first 10 lines of a file.
tail -n5 <file.txt>View the last 5 lines of a file.
vim <file>Edit a file using the Vim editor.
sed ‘s/old/new/g’ <file>Search and replace text in a file.
grep <pattern> <file>Search for a pattern in a file.
awk ‘/pattern/ {print $1}’ <file>Pattern scanning and processing in files.
cat <file>Concatenate and display file content.
tee <file>Write output to a file and display it on the terminal.
uniq <file>Remove duplicate lines from a file.

File Compression

CommandDescription
gzip <file>Compress a file.
gunzip <file>Decompress a file.
tar -cvf <archive.tar> <files>Create a tar archive.
tar -xvf <archive.tar>Extract a tar archive.

Process Management

CommandDescription
ps auxDisplay detailed information about running processes.
topDisplay real-time system stats, including process info.
kill <process_id>Terminate a process by its ID.
historyShow command history.
chmod 755 <file>Change file permissions.
chown user:group <file>Change file ownership.

Disk and File System

CommandDescription
df -hDisplay disk space usage in human-readable format.
du -sh <directory>Display the size of a directory.
mountMount a filesystem.
umount <device>Unmount a filesystem.
lsblkList information about block devices.

User and Group Management

CommandDescription
useradd <username>Create a new user.
usermod -l <newname> <oldname>Change a username.
passwd <username>Set or update a user’s password.
groupadd <groupname>Create a new group.
gpasswd -M <users> <group>Add multiple users to a group.
usermod -L <username>Lock a user account.
usermod -U <username>Unlock a user account.

Networking and System Monitoring

CommandDescription
ifconfigDisplay network interface information.
ping <hostname>Test network connectivity.
nslookup <domain>Get DNS information for a domain.
netstat -tulnShow open ports and network connections.
hostnameDisplay or set the system’s hostname.
curl <url>Download files or interact with APIs.
scp <file> <user@host:path>Securely copy files to a remote system.
rsync -avz <source> <destination>Sync files between two locations.

Package Management (RPM/YUM)

CommandDescription
rpm -ivh <package.rpm>Install an RPM package.
rpm -qaList installed RPM packages.
yum install <package>Install software via YUM.
yum update <package>Update installed software.
yum remove <package>Remove software via YUM.

Scheduling and Automation

CommandDescription
crontab -eEdit cron jobs for scheduling tasks.
crontab -lList scheduled cron jobs.
systemctl start <service>Start a system service.
systemctl stop <service>Stop a system service.
systemctl status <service>Check the status of a service.

Security and Permissions

CommandDescription
chmod <permissions> <file>Change file permissions (e.g., 755).
chown <user>:<group> <file>Change file ownership.
ssh-keygenGenerate SSH key pairs.
ssh <user@hostname>Connect to a remote system securely via SSH.
scp <file> <remote_host:path>Securely copy files over SSH.

This Linux Command Cheat Sheet provides a quick reference to some of the most commonly used commands in Linux. Use it to improve your productivity and manage Linux systems more effectively. For deeper exploration of these commands, check out the man pages (man <command>)

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
blank

How to Prepare for the AWS Certified Solutions Architect – Associate Exam

Next Post
blank

Securing Amazon S3 Buckets in AWS

Related Posts