Skip to content

Linux Commands Cheat Sheet (AI Generated 😄 )

User Management

Adding a User to the Sudo Group

bash
sudo usermod -aG sudo username
Replace username with the actual username you want to add to the sudo group.

Creating a New User

bash
sudo useradd -m -s /bin/bash username
Replace username with the actual username you want to create.

Deleting a User

bash
sudo userdel -r username
Replace username with the actual username you want to delete.

Changing a User's Password

bash
sudo passwd username
Replace username with the actual username whose password you want to change.

File and Directory Management

Creating a New Directory

bash
mkdir directory_name
Replace directory_name with the actual name of the directory you want to create.

Deleting a Directory

bash
rmdir directory_name
Replace directory_name with the actual name of the directory you want to delete.

Copying a File

bash
cp source_file destination_file
Replace source_file with the actual name of the file you want to copy, and destination_file with the actual name of the file you want to create.

Moving a File

bash
mv source_file destination_file
Replace source_file with the actual name of the file you want to move, and destination_file with the actual name of the file you want to create.

Changing File Permissions

bash
chmod permissions file_name
Replace permissions with the actual permissions you want to set (e.g., 755), and file_name with the actual name of the file whose permissions you want to change.

Changing File Ownership

bash
chown user:group file_name
Replace user with the actual username you want to set as the owner, group with the actual group name you want to set as the group, and file_name with the actual name of the file whose ownership you want to change.

Group Management

Adding a User to a Group

bash
sudo usermod -aG group_name username
Replace group_name with the actual name of the group you want to add the user to, and username with the actual username you want to add.

Creating a New Group

bash
sudo groupadd group_name
Replace group_name with the actual name of the group you want to create.

Deleting a Group

bash
sudo groupdel group_name
Replace group_name with the actual name of the group you want to delete.

Adding a Folder to a Group

bash
sudo chgrp group_name folder_name
Replace group_name with the actual name of the group you want to add the folder to, and folder_name with the actual name of the folder you want to add.

System Information

Displaying System Information

bash
uname -a
Displays information about the system, including the kernel version, hostname, and architecture.

Displaying CPU Information

bash
lscpu
Displays information about the CPU, including the number of cores, threads, and architecture.

Displaying Memory Information

bash
free -m
Displays information about the system's memory, including the total amount of memory, used memory, and free memory.

Displaying Disk Information

bash
df -h
Displays information about the system's disks, including the total size, used space, and available space.

Networking

Displaying Network Interfaces

bash
ip addr show
Displays information about the system's network interfaces, including the IP address, subnet mask, and gateway.

Displaying Network Routes

bash
ip route show
Displays information about the system's network routes, including the destination IP address, gateway IP address, and interface.

Displaying Network Statistics

bash
netstat -s
Displays statistics about the system's network activity, including the number of packets sent and received, errors, and dropped packets.

Security

Updating the System

bash
sudo apt update && sudo apt upgrade
Updates the system's package list and upgrades all installed packages to the latest version.

Installing a Firewall

bash
sudo apt install ufw
Installs the Uncomplicated Firewall (UFW) package, which provides a simple way to configure the system's firewall.

Enabling the Firewall

bash
sudo ufw enable
Enables the UFW firewall, which will block all incoming traffic by default.

Allowing Incoming Traffic on a Specific Port

bash
sudo ufw allow port_number
Allows incoming traffic on a specific port number, replacing `

Allowing Incoming Traffic on a Specific Port

bash
sudo ufw allow port_number
Allows incoming traffic on a specific port number, replacing port_number with the actual port number you want to allow (e.g., 22 for SSH).

Blocking Incoming Traffic on a Specific Port

bash
sudo ufw deny port_number
Blocks incoming traffic on a specific port number, replacing port_number with the actual port number you want to block.

Checking the Firewall Status

bash
sudo ufw status
Displays the current status of the UFW firewall, including the list of allowed and blocked ports.

Process Management

Killing a Process

bash
kill process_id
Kills a process with the specified process_id.

Killing a Process by Name

bash
pkill process_name
Kills a process with the specified process_name.

Checking Running Processes

bash
ps aux
Displays a list of all running processes, including their process IDs, user IDs, and command lines.

Checking System Resource Usage

bash
top
Displays a real-time view of system resource usage, including CPU usage, memory usage, and disk usage.

File System Management Creating a New File System

bash
mkfs file_system_type device_name
Creates a new file system on a device, replacing file_system_type with the type of file system you want to create (e.g., ext4), and device_name with the name of the device you want to create the file system on.

Mounting a File System

bash
mount device_name mount_point
Mounts a file system on a device, replacing device_name with the name of the device you want to mount, and mount_point with the directory where you want to mount the file system.

Unmounting a File System

bash
umount device_name
Unmounts a file system from a device, replacing device_name with the name of the device you want to unmount.

Checking Disk Usage

bash
df -h
Displays a list of all mounted file systems, including their disk usage and available space.

Network File System (NFS) Management

Mounting an NFS Share

bash
mount -t nfs server_name:share_name mount_point
Mounts an NFS share from a server, replacing server_name with the name of the server, share_name with the name of the share, and mount_point with the directory where you want to mount the share.

Unmounting an NFS Share

bash
umount mount_point
Unmounts an NFS share from a mount point, replacing mount_point with the directory where the share is mounted.

Checking NFS Shares

bash
showmount -e server_name
Displays a list of all NFS shares exported by a server, replacing server_name with the name of the server.

Conclusion

This cheat sheet provides a comprehensive list of Linux commands for various tasks, including user management, file and directory management, system information, networking, security, process management, file system management, and NFS management. These commands can help you perform common tasks and troubleshoot issues in a Linux environment.

The content provided is generated with the help of artificial intelligence (AI) and may contain inaccuracies or outdated information due to the limitations of AI. While I strive to review and validate the content, some errors or inaccuracies may still be present in the final output. Please use this content as a general guide only and verify any critical information through reputable sources before relying on it. I appreciate your understanding and feedback in helping us improve the accuracy and quality of our AI-generated content."