System
LINUX COMMANDS CHEAT SHEET File Commands
uname Displays system information: kernel ls -al Lists all files, detailed information, in long
version, machine type, and more. format.
uname -r Displays the running Linux kernel's release pwd Displays the present working directory's
version. path.
uptime Shows current time, system uptime, users, mkdir dir1 Creates a new directory named dir1.
and load averages. rm file1 Deletes the file named file1.
hostname Shows the system hostname rm -f file2 Forcefully deletes the file named file2.
hostname -i Displays the IP address of the current host. rm -r dir1 Recursively removes directory dir1 and its
last reboot Shows last reboot times and durations in contents.
logs. rm -rf dir1 Forcefully deletes directory dir1 and its
date Displays the current date and time contents.
information. cp file1 file2 Copies file1, creating or overwriting file2.
timedatectl Displays detailed system clock and time cp -r dir1 dir2 Copies dir1 to dir2, including
zone information. subdirectories.
cal Displays a simple calendar of the current mv file1 file2 Renames or moves file1 to file2.
month.
w Shows who is logged on and their activity. ln -s /path/to/ Creates symbolic link named link name to
_
file name link name
_ _ file name.
_
whoami Displays the username of the current user. touch file1 Creates an empty file named file1.
finger username Displays information about a user named cat file1 Creates/overwrites file1, awaiting standard
'username'. >
input.
more file1 Displays file1 content, paginating through
Hardware output.
head file1 Displays the first ten lines of file1.
dmesg Displays messages from the kernel's ring tail file1 Displays the last ten lines of file1.
buffer. gpg -c file1 ncrypts file1 with symmetric cipher using
cat /proc/cpuinfo Displays detailed information about the E
passphrase.
CPU. gpg [Link] Decrypts [Link], prompting for the
cat /proc/meminfo Displays detailed system memory usage passphrase.
information. wc Counts words, lines, and characters in files.
lshw Lists detailed hardware configuration of the xargs xecutes commands with piped or file-
system. E
provided arguments.
lsblk Lists information about all available block
devices.
free -m Shows system memory usage in P ro ess elated
c R
megabytes.
lspci -tv Displays PCI devices in tree format, ps Displays a snapshot of current processes.
verbosely. ps aux grep telnet
| Displays running telnet processes with
lsusb -tv Shows USB devices as a tree, verbosely. details.
dmidecode Displays hardware information from system pmap Shows memory map of a process.
BIOS top Displays dynamic real-time view of running
hdparm -i /dev/sda Displays information of disk /dev/sda. tasks.
badblocks -s /dev/ Checks /dev/sda for bad blocks, showing kill 12 34 Terminates the process with PID 12 . 34
sda progress. killall proc K ills all processes named 'proc'.
pkill process-name erminates processes with the name.
User Management
T
bg Resumes suspended obs in the
j
background
id Displays the user's UID, GID, and groups. fg Brings a suspended ob to foreground
j
last Shows list of last logged-in users. fg n Brings ob number 'n' to foreground.
j
who Displays who is currently logged in. lsof Lists all open files and processes.
groupadd admin Creates a new user group named admin. renice 1 PID 9 Changes priority of process with given PID.
adduser Sam Creates a new user account named Sam. pgrep firefox Displays Process ID s for firefox
( )
userdel Sam Deletes the user account named Sam. processes.
usermod Modifies properties of an existing user pstree Displays a tree of running processes.
account.
LINUX COMMANDS CHEAT SHEET
File Permission Install Source (Compilation)
chmod 644 /data/ Sets the permissions of the file /data/test.c ./configure Checks system compatibility and
test.c to be read/write for the owner, and read- generates makefile for software
only for the group and others. installation.
chmod 755 /dir1 Assigns read, write, and execute make Compiles code by following instructions in
permissions to the owner, and read and the Makefile.
execute permissions to the group and
make install Installs compiled code into specified
others for the directory /dir1.
system locations.
chown bob:devops Changes file 'filename' ownership to 'bob'
filename and 'devops'.
Search
chown Change owner and group of the directory.
ownername:groupn
grep pattern file Search for a given pattern within the file.
ame directory
grep -r pattern dir1 Recursively searches for the specified
"pattern" within the "dir1" directory and its
Network subdirectories
locate file Finds files named "file" using prebuilt
ip addr show Displays all network interfaces and their
database.
information.
find /home -name Searches "/home" directory for files named
ip address add Assigns IP address [Link] to interface
index "index" recursively.
[Link]/24 dev eth0.
eth0 find /home -size Finds files over 10000k size in /home
+10000k directory.
ifconfig Shows network interfaces and their
configuration.
ping host Sends ICMP packets, measures round-trip
Login
time to "host".
ssh user@hostname Initiates SSH connection to specified
whois domain Retrieves and displays domain's
hostname.
registration information.
ssh -p port_ number Initiates SSH connection using specific
dig domain Queries DNS, provides domain's DNS
user@hostname port.
information.
Connect to the host Securely connect to the system via SSH
dig -x host Resolves IP address to hostname, shows
via telnet default port default port 22
DNS information.
2 3
host [Link] Performs an IP lookup for the domain name
telnet host Connect to the host via telnet default port
wget file_ path Downloads file from specified path. 3
2 .
netstat Displays various network-related
information and statistics.
File Transfer
Compression / Archives scp [Link] Copies [Link] to remote host's specified
remoteuser@remote_ directory.
host:/remote/
tar -cf [Link] / Creates a tar archive of /home/ubuntu
directory
home/ubuntu directory.
rsync -a /home/ Synchronizes content from source
tar -xf [Link] Extracts files from "[Link]" archive.
ubuntu /backup/ directory to destination
tar -zcvf Creates compressed "[Link]"
directory,preserving attributes.
[Link] /home/ archive of "/home/ubuntu"
rsync -a /var/www/ Synchronizes local directory to remote,
ubuntu
web/ preserving attributes.
gzip file1 Compresses "file1" into "[Link]", original is
user@remote_host:/
removed.
backup/web_backup/
Install Packages Disk Usage
rpm -i pkg _ [Link] Installs the package "pkg _ [Link]" using
df -h Displays human-readable disk space usage
RPM Package Manager.
for all mounted filesystems.
rpm -e pkg _ name Uninstalls the specified RPM package. df -i Displays inode usage information for all
dnf install pkg _ name Installs the specified package using DNF. mounted filesystems.
pacman -S Installs the specified package using fdisk -l Lists all partitions and their information on
pkg _ name Pacman. all drives.
Directory Traverse du -sh /dir1 Displays summary of total disk usage size
of /dir1, human-readable.
findmnt Displays a list of all mounted filesystems
cd .. Navigate to the parent directory. and their properties.
cd Changes the current directory to the user's mount device-path Mounts the device at the specified
home. mount-point filesystem mount point.
cd /mnt Changes the current directory to "/mnt".