1) System
uname Displays Operating system name
uname -r Displays kernel release information
uptime Displays how long the system has been running including load average
hostname Shows the system hostname
hostname -i Displays the IP address of the system
last reboot Shows system reboot history
date Displays current system date and time
timedatectl Query and change the System clock
cal Displays the current calendar month and day
w Displays currently logged in users in the system
whoami Displays who you are logged in as
tree Displays tree system of files
2) Hardware
dmesg Displays bootup messages
cat /proc/cpuinfo Displays more information about CPU e.g model, model name, cores, vendor id
cat /proc/meminfo Displays more information about hardware memory e.g. Total and Free memory
lscpu Displays information about cpu and processing unit.
lsblk Displays block devices related information
free -m Displays free and used memory in the system (-m flag indicates memory in MB)
df -h Displays mounted spaces
lspci -tv Displays PCI devices in a tree-like diagram
dmidecode Displays hardware information from the BIOS
Fdisk -l To list partition tables.
ps To see all the running process
Kill -9 pid To kill that process
3) File Commands
touch filename To Create a file
mkdir directory-name To create a directory
ls -al Lists files - both regular & hidden files
rm filename Removes a file
rm -f filename Forcefully removes a file
rm -r directory-name Removes a directory recursively
rm -rf directory-name Removes a directory forcefully and recursively
cp file1 file2 Copies the contents of file1 to file2
cp -r dir1 dir2 Recursively Copies dir1 to dir2. dir2 is created if it does not exist
mv file1 file2 Renames file1 to file2
ln -s /path/to/filename link-
Creates a symbolic link to filename
name
touch filename Creates a new file
cat > filename Places standard input into a file
more filename Outputs the contents of a file
head filename Displays the first 10 lines of a file
tail filename Displays the last 10 lines of a file
gpg -c filename Encrypts a file
gpg -c filename.gpg Decrypts a file
wc Prints the number of bytes, words and lines in a file
xargs Executes commands from standard input
4) Users
id Displays the details of the active user e.g. uid, gid, and groups
last Shows the last logins in the system
who Shows who is logged in to the system
groupadd "admin" Adds the group 'admin'
adduser "Sam" Adds user Sam
userdel "Sam" Deletes user Sam
usermod Used for changing / modifying user information
6) File Permission
chmod octal filename Change file permissions of the file to octal
Example
Set rwx permissions to owner, group and everyone (everyone else
chmod 777 /data/test.c
who has access to the server)
chmod 755 /data/test.c Set rwx to the owner and r_x to group and everyone
chmod 766 /data/test.c Sets rwx for owner, rw for group and everyone
chown owner user-file Change ownership of the file
chown owner-user:owner-group
Change owner and group owner of the file
filename
chown owner-user:owner-group
Change owner and group owner of the directory
directory
7) Network
ip addr show Displays IP addresses and all the network interfaces
ip address add 192.168.0.1/24 dev eth0 Assigns IP address 192.168.0.1 to interface eth0
ifconfig Displays IP addresses of all network interfaces
ping command sends an ICMP echo request to establish a
ping localhost
connection to server / PC
whois domain Retrieves more information about a domain name
dig domain Retrieves DNS information about the domain
dig -x host Performs reverse lookup on a domain
host google.com Performs an IP lookup for the domain name
hostname -i Displays local IP address
wget filename Downloads a file from an online source
netstat -r Displays Kernel IP routing table
8) Compression/Archives
tar -cf home.tar home<:code> Creates archive file called 'home.tar' from file 'home'
tar -xf files.tar Extract archive file 'files.tar'
tar -zcvf home.tar.gz source-folder Creates gzipped tar archive file from the source folder
gzip file Compression a file with .gz extension
9) Install Packages
rpm -i pkg_name.rpm Install an rpm package
rpm -e pkg_name Removes an rpm package
dnf install pkg_name Install package using dnf utility
11) Search
grep 'pattern' files Search for a given pattern in files
grep -r pattern dir Search recursively for a pattern in a given directory
locate file Find all instances of the file
find /home/ -name "index" Find file names that begin with 'index' in /home folder
find /home -size +10000k Find files greater than 10000k in the home folder
12) Disk Usage
df -h Displays free space on mounted systems
df -i Displays free inodes on filesystems
fdisk -l Shows disk partitions, sizes, and types
du -sh Displays disk usage in the current directory in a human-readable format
findmnt Displays target mount point for all filesystems
mount device-path mount-point Mount a device
13) Directory Traverse
cd .. Move up one level in the directory tree structure
cd ~ Change directory to $HOME directory
cd /test Change directory to /test directory