CheatSheet For Linux
A ] Package Management
apt
(Advanced Package Tool):apt
is a command-line package management tool for Debian-based Linux distributions like Ubuntu.Syntax:
Install a package:
sudo apt install package_name
Remove a package:
sudo apt remove package_name
Update package list:
sudo apt update
Upgrade installed packages:
sudo apt upgrade
yum
(Yellowdog Updater, Modified):yum
is a package manager used on Red Hat-based Linux distributions like CentOS and Fedora.Syntax:
Install a package:
sudo yum install package_name
Remove a package:
sudo yum remove package_name
Update package list:
sudo yum check-update
Upgrade installed packages:
sudo yum update
dnf
(Dandified YUM):dnf
is a more modern package manager and is used on recent versions of Fedora and CentOS.Syntax:
Install a package:
sudo dnf install package_name
Remove a package:
sudo dnf remove package_name
Update package list:
sudo dnf check-update
Upgrade installed packages:
sudo dnf upgrade
rpm
(RPM Package Manager):rpm
is a low-level package management tool used for installing, querying, and managing individual RPM packages.Syntax:
Install an RPM package:
sudo rpm -i package.rpm
Query package information:
rpm -q package_name
Remove a package:
sudo rpm -e package_name
apt-get
(Debian-specific):apt-get
is a predecessor to theapt
command and is commonly used on Debian-based systems.Syntax (similar to
apt
):Install a package:
sudo apt-get install package_name
Remove a package:
sudo apt-get remove package_name
Update package list:
sudo apt-get update
Upgrade installed packages:
sudo apt-get upgrade
snap
(Snap Package Manager):snap
is a universal package manager used on various Linux distributions to install and manage snap packages, which are self-contained applications.Syntax:
Install a snap package:
sudo snap install package_name
Remove a snap package:
sudo snap remove package_name
List installed snap packages:
snap list
Update all snap packages:
sudo snap refresh
B ] System Information
du
- Disk Usage
Syntax: du [options] [directory/file]
Explanation: The du
command is used to estimate file and directory space usage on a Linux system. By default, it shows the space usage in kilobytes. You can specify a directory or file as an argument, and it will display the space used by that specific item. Various options can be used to customize the output, such as -h
for human-readable sizes or -s
for summary.
df
- Disk Free
Syntax: df [options] [file/directory]
Explanation: The df
command displays information about the disk space on a Linux system. It shows the disk usage statistics for all mounted filesystems, including the total size, used space, and available space. The default output is in kilobytes. Use the -h
option for human-readable sizes.
free
- Memory Usage
Syntax: free [options]
Explanation: The free
command is used to display information about the system's RAM (Random Access Memory) and swap space usage. It shows the total, used, and free memory in kilobytes. You can use options like -h
to display sizes in a more human-readable format.
uname
- System Information
Syntax: uname [options]
Explanation: The uname
command provides system information, including the kernel name, network node hostname, kernel release, kernel version, machine hardware name, and operating system. Common options include -a
to display all information or -r
to show the kernel release.
lscpu
- CPU Information
Syntax: lscpu [options]
Explanation: The lscpu
command displays information about the CPU (Central Processing Unit) on a Linux system. It provides details such as the number of CPU cores, architecture, CPU family, and more. Common options include -c
for showing CPU core details or -p
for showing a list of online CPUs.
lshw
- Hardware Information
Syntax: lshw [options]
Explanation: The lshw
command is used to display detailed information about the hardware components of your system, including the CPU, memory, storage devices, network adapters, and more. It can provide a comprehensive hardware inventory. Common options include -short
for a shorter summary or -class
to list hardware components by class.
lsblk
- List Block Devices
Syntax: lsblk [options]
Explanation: The lsblk
command lists information about block devices (storage devices) on your system, such as hard drives and partitions. It provides details like device names, sizes, and mount points. Common options include -a
to show all devices, even if they're not mounted, or -f
to display additional information.
C ] File & Directory Management
- ls (List):
Syntax: ls [options] [file/directory]
Explanation: The ls
command is used to list the files and directories in the current directory by default. You can provide various options to customize the listing, such as -l
for a long format, -a
to display hidden files, and more.
- rm (Remove):
Syntax: rm [options] [file/directory]
Explanation: The rm
command is used to remove files and directories. Be very careful when using this command, as it permanently deletes files, and there is no way to recover them without a backup. Use options like -r
for recursive removal when deleting directories.
- cp (Copy):
Syntax: cp [options] source destination
Explanation: The cp
command is used to copy files and directories. You specify the source file or directory and the destination where you want to copy it. Use options like -r
for recursive copy when dealing with directories.
- mv (Move/Rename):
Syntax: mv [options] source destination
Explanation: The mv
command is used to move (rename) files and directories. It can also be used to rename files or move them to a different location. This command essentially changes the path or name of the file.
- pwd (Print Working Directory):
Syntax: pwd
Explanation: The pwd
command is used to print the current working directory's absolute path. It helps you determine your current location in the file system.
6.touch:
Syntax: touch [options] filename
Explanation: The touch
command is used to create a new empty file with the specified name. If the file already exists, it updates the file's modification timestamp. It's often used to create placeholder files.
- mkdir (Make Directory):
Syntax: mkdir [options] directoryname
Explanation: The mkdir
command is used to create a new directory with the specified name. You can specify options for creating parent directories or setting permissions.
D ] File View and Editing Management
cat
(concatenate):
Syntax: cat [options] [file]
Explanation: The cat
command is used to display the content of one or more files. You can specify one or more file names as arguments, and cat
will print their contents to the standard output. It is often used for viewing or combining the contents of files.
less
:
Syntax: less [options] [file]
Explanation: The less
command is a pager that allows you to view the contents of a file one screen at a time. It is useful for browsing through large files, and you can navigate through the file using various keyboard commands.
more
:
Syntax: more [options] [file]
Explanation: Similar to less
, the more
command is used as a pager to view the contents of a file one screen at a time. It is a simpler pager compared to `less and provides basic navigation options.
vi
Vim - Vi IMproved):
Syntax: vi [file]
Explanation: Vim is a powerful and highly configurable text editor. To open a file in Vim, you simply type vi
followed by the name of the file. Once inside Vim, you can navigate, edit, and save the file using various commands and modes.
5.find
:
Syntax: find [path] [expression]
Explanation: The find
command is used to search for files and directories within a specified path. You can provide various search criteria and expressions to locate files that match specific patterns or properties.
grep
(Global Regular Expression Print):Syntax:
grep [options] pattern [file(s)]
Explanation:
grep
is a command-line utility used for searching text patterns in files. You specify a pattern, andgrep
will display lines from the input files that match the pattern. It is a powerful tool for text searching and manipulation.vim
:Syntax:
vim [file]
Explanation: Vim is an enhanced version of the
vi
text editor, and it offers advanced features and customization options. The syntax for opening a file in Vim is the same asvi
, and you can use Vim's extensive functionality for editing and navigation.nano
:Syntax:
nano [file]
Explanation:
nano
is a simple and user-friendly text editor often used in the terminal. It provides an easy-to-use interface for editing files, making it a good choice for beginners who may not be familiar with more advanced text editors like Vim.
E ] User and Group Management
passwd
- Change user passwordSyntax: passwd [OPTIONS] [USERNAME]
Explanation: The
passwd
command is used to change a user's password on a Linux system. When used without any options, it prompts you to enter the current password and then the new password twice. You can also specify a username to change the password for a specific user.usermod
- Modify user accountSyntax:usermod [OPTIONS] [USERNAME] Explanation: The
usermod
command is used to modify various attributes of a user account. You can use this command to change a user's home directory, shell, group membership, and more. It offers several options to control what aspects of the user account to modify.useradd
- Create a new user accountSyntax:useradd [OPTIONS] USERNAME Explanation: The
useradd
command is used to create a new user account on a Linux system. You need to provide a username as an argument. You can specify additional options to set user attributes like the home directory, shell, and more.userdel
- Delete a user accountSyntax: userdel [OPTIONS] USERNAME
Explanation: The
userdel
command is used to delete a user account from the system. It also removes the user's home directory and mail spool by default. You should be careful when using this command as it permanently removes a user and their data.groups
- Display group memberships for a userSyntax: groups [USERNAME]
Explanation: The
groups
command displays the group memberships for a user. If you provide a username as an argument, it will show the groups that the user belongs to. If no username is provided, it will display the groups for the currently logged-in user.groupadd
- Create a new groupSyntax: groupadd [OPTIONS] GROUPNAME
Explanation: The
groupadd
command is used to create a new group on the system. You need to specify a group name as an argument. You can use additional options to set attributes for the group, such as the group ID.groupdel
- Delete a groupSyntax: groupdel [OPTIONS] GROUPNAME
Explanation: The
groupdel
command is used to delete a group from the system. It also removes any users that are associated with the group. Be cautious when using this command, as it will permanently delete the group and its members.
F ] Network Configuration and Monitoring
ip
:Syntax:
ip [OPTIONS] OBJECT { COMMAND | help }
Explanation: The
ip
command is used to manage network interfaces, routes, and various networking settings on a Linux system. It is a powerful tool for configuring and monitoring network-related information.ss
(Socket Statistics):Syntax:
ss [OPTIONS] [ FILTER ]
Explanation:
ss
is a command-line utility that provides socket statistics. It displays information about network sockets, including listening and established connections, and can be used to troubleshoot network-related issues.nc
(Netcat):Syntax:
nc [OPTIONS] HOST PORT
Explanation: Netcat is a versatile networking utility that can be used for various purposes, including connecting to remote servers over different protocols (TCP or UDP) and port scanning. It can also be used for creating network connections and transferring data.
ssh
(Secure Shell):Syntax:
ssh [OPTIONS] [USER@]HOST [COMMAND]
Explanation: The
ssh
command is used for secure remote access to another system over a network. It provides an encrypted connection for secure communication and can be used to log in to remote servers or execute commands on remote systems.ping
:Syntax:
ping [OPTIONS] HOST
Explanation: The
ping
command is used to test network connectivity between your local machine and a remote host by sending ICMP (Internet Control Message Protocol) echo requests and waiting for echo replies. It is a simple tool to check if a host is reachable.netstat
(Network Statistics):Syntax:
netstat [OPTIONS] [FILTER]
Explanation: The
netstat
command displays various network-related statistics, including active network connections, routing tables, and interface statistics. It provides information about network activity and can be useful for diagnosing network issues.ifconfig
(Interface Configuration):Syntax:
ifconfig [INTERFACE] [OPTIONS]
Explanation: The
ifconfig
command is used to configure and display information about network interfaces on a Linux system. It can be used to view network interface settings, assign IP addresses, and more. Note thatip
has largely replacedifconfig
in modern Linux distributions.traceroute
(Trace Route):Syntax:
traceroute [OPTIONS] HOST
Explanation: The
traceroute
command is used to trace the route that packets take from your local machine to a remote host on the network. It displays the list of hops (routers) between your system and the destination host, helping to diagnose network routing issues.
G ] Process Management
ps
(Process Status):Syntax:
ps [options]
Explanation: The
ps
command is used to display information about the currently running processes on a Linux system. By default, it shows a list of processes running in the current terminal session. You can use various options to customize the output and filter processes based on criteria like user, terminal, or process state.top
(Task Manager):Syntax:
top
Explanation: The
top
command provides a dynamic and real-time view of system performance and a list of processes. It displays a constantly updating list of running processes, system resource usage (CPU, memory, etc.), and other system statistics. You can press 'q' to quit thetop
interface.kill
(Terminate a Process):Syntax:
kill [signal] PID
Explanation: Thekill
command is used to send a signal to a specified process to terminate it. The default signal is SIGTERM (15), which asks the process to gracefully terminate. You can use theps
command to find the PID of the process you want to kill.killall
(Terminate Processes by Name):Syntax:
killall [options] process_name
Explanation:
killall
is used to send a signal to all processes with a specific name. It's useful for terminating multiple instances of a process with the same name. Be cautious when using this command, as it can potentially kill unintended processes.pstree
(Process Tree):Syntax:
pstree [options] [user]
Explanation: The
pstree
command displays running processes in a hierarchical tree structure, showing parent-child relationships between processes. It can be helpful in visualizing how processes are related to each other in a system.htop
(Interactive Process Viewer):Syntax:
htop
Explanation:
htop
is an enhanced and interactive alternative to thetop
command. It provides a real-time view of system and process information with a more user-friendly and customizable interface. You can navigate through the list of processes, send signals, and interactively manage processes within thehtop
interface.
I hope you enjoy the blog post!
If you do, please show your support by giving it a like β€, leaving a comment π¬, and spreading the word π’ to your friends and colleagues π