Linux Commands Cheat Sheet

Linux Commands Cheat Sheet


Do you know that there are literally hundreds of Linux commands? Below you will find a Linux "cheat sheet" that breaks some of the most commonly used commands by category. To download the Linux commands cheat sheet pdf, scroll to the bottom of the page.

Basic Linux Commands in below :

1 – SYSTEM INFORMATION

# Display Linux system information
uname -a

# Display kernel release information
uname -r

# Show which version of redhat installed
cat /etc/redhat-release

# Show how long the system has been running + load
uptime

# Show system host name
hostname

# Display the IP addresses of the host
hostname -i

# Show system reboot history
last reboot

# Show the current date and time
timedatectl

# Show this month's calendar
cal

# Display who is online
w

# Who you are logged in as
whoami

#Display information about the user.
finger username

2 – HARDWARE INFORMATION

# Display messages in kernel ring buffer
dmesg

# Display CPU information
cat /proc/cpuinfo

# Display memory information
cat /proc/meminfo

# Display information about system's hardware configuration
lshw

# Display free and used memory ( -h for human readable, -m for MB, -g for GB.)
free -h

# Display PCI devices
lspci -tv

# Display USB devices
lsusb -tv

# Display DMI/SMBIOS (hardware info) from the BIOS
dmidecode

# Show info about disk sda
hdparm -i /dev/sda

# Perform a read speed test on disk sda
hdparm -tT /dev/sda

# Test for unreadable blocks on disk sda
badblocks -s /dev/sda


3 – PERFORMANCE MONITORING AND STATISTICS

# Display and manage the top processes
top

# Interactive process viewer (top alternative)
htop

# Display processor related statistics
mpstat 1

# Display virtual memory statistics
vmstat 1


# Capture and display all packets on interface eth0
tcpdump -i eth0

# Monitor all traffic on port 80 ( HTTP )
tcpdump -i eth0 'port 80'

# Display free and used memory ( -h for human readable, -m for MB, -g for GB.)
free -m


4 – USER INFORMATION AND MANAGEMENT

# Display the user and group ids of your current user.
id

# Display the last users who have logged onto the system.
last

# Show who is logged into the system.
who

# Show who is logged in and what they are doing.
w

# Create a group named "test".
groupadd test

# Create an account named john, with a comment of "John Smith" and create the user's home directory.
useradd -c "John Smith" -m john

# Delete the john account.
userdel john

# Add the john account to the sales group
usermod -aG sales john

5 – FILE AND DIRECTORY COMMANDS

# List all files in a long listing (detailed) format
ls -al

# Display the present working directory
pwd

# Create a directory
mkdir directory

# Remove (delete) file
rm file

# Remove the directory and its contents recursively
rm -r directory

# Force removal of file without prompting for confirmation
rm -f file

# Forcefully remove directory recursively
rm -rf directory

# Copy file1 to file2
cp file1 file2

# Copy source_directory recursively to destination. If destination exists, copy source_directory into destination, otherwise create destination with the contents of source_directory.
cp -r source_directory destination

# Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2
mv file1 file2

# Create symbolic link to linkname
ln -s /path/to/file linkname

# Create an empty file or update the access and modification times of file.
touch file

# View the contents of file
cat file

# Browse through a text file
less file

# Display the first 10 lines of file
head file

# Display the last 10 lines of file
tail file

# Display the last 10 lines of file and "follow" the file as it grows.
tail -f file

#Plce standard input into a file
cat > filename

#Output the content of a file
more filename

#Encrypt a file
gpg -c filename

#Decrypt a file
gpg filename.gpg

#Print the number of bytes,word and lines in a file
wc

#Execute commands from standard input
xargs

6 – PROCESS MANAGEMENT

# Display your currently running processes
ps

# Display all the currently running processes on the system.
ps -ef

# Display process information for processname
ps -ef | grep processname

#search for the id of the process 'telnet'
ps aux |grep 'telnet'

# Display and manage the top processes
top

# Kill process with process ID of pid
kill pid

# Kill all processes named processname
killall processname


# Display stopped or background jobs
bg

# Brings the most recent background job to foreground
fg

# Brings job n to the foreground
fg n

#list files that are open by processes
lsof

# Maakes a process run with very low priority
renice 19 pid

#Find firefox process ID
pgrep firefox

#Visualizing processes in tree model
pstree


7 – FILE PERMISSIONS

# Change file permission of the file to local
chmod 777 /data/text.txt

#Set rwx to the owner and r-x to group and everyone
chmod 755 /data/test.txt

#change ownershipo of the file
chown owner filename

#change owner aand group owner of the file and dir
chown owneruser:ownergroup file_name
chown owneruser:ownergroup dir_name    

     
8 – NETWORKING

#Display IP address and all the network interfaces
ip addr show

#Assigns IP address 192.168.0.1 to interface eth0
ip address add 192.168.0.1/24 dev eth0

# Display all network interfaces and ip address
ifconfig 

# Query or control network driver and hardware settings
ethtool eth0

# Send ICMP echo request to host
ping host

# Retrueves more information about aa domain name
whois domain

# Display DNS information for domain
dig domain

#Perform reverse lookup on a domain
dig -x host

# Perform an IP lookup for the domain name
 host 'domain name'

# Display local ip addresses
hostname -i

# Download a file from an online source 
wget http://domain.com/file

# Display all active listening tcp and udp ports 
netstat -tupln


9 – ARCHIVES (TAR FILES)

# Create archive file called home.tar from file 'home'.
tar cf home.tar home

# Extract the archive file file.tar.
tar xf file.tar

# Create a gzip compressed tar file name archive.tar.gz.
tar zcvf archive.tar.gz directory

# Compression a gzip compressed file with .gz extension.
tar xzf archive.tar.gz



10 – INSTALLING PACKAGES

# Search for a package by keyword.
yum search keyword

# Install package.

# Install an rom package 
rpm -i package.rpm

# Remove an rpm package.
rpm -e  pkg_name

# Install package using dnf utility.
dnf install pkg_name

11-Install Source (Compiltion)
./configure
make
make install


12 – SEARCH

# Search for given pattern in file
grep pattern file

# Search recursively for a pattern in a given directory
grep -r pattern directory

# Find files and directories by name
locate name

# Find files name thaat begin with index in /home folder.
find /home -name "index"

# Find files greater than 10000KB in the  /home folder.
find /home -size +10000k

13 – SSH LOGINS

# Securely Connect to host as user.
ssh user@host

# Securely Connect to host using specified port
ssh -p port user@host

#Securely connect to the system via SSH default port 22
ssh host

#Connect to host via telnet default port 23
telnet host


14 – FILE TRANSFERS

# Secure copy file1.txt to the /tmp folder on server
scp file1.txt server2/tmp


# Synchronize contents in /home/apps directory with  /backups directory

rsync -a /home/apps /backups/


15 – DISK USAGE

# Display free and used space on mounted filesystems
df -h

# Display free and used inodes on mounted filesystems
df -i

# Show disks partitions sizes and types
fdisk -l

# Display total disk usage off the current directory
du -sh

#Display target mount point for all filesystem
findmnt

#mount a device
mount device-path mount-point

16 – DIRECTORY Traverse

# To go up one level of the directory tree.  
cd ..

# Go to the $HOME directory
cd

# Change to the /test directory
cd /test


Book Name: Linux Commands Cheat Sheet
Book size : 90.7 KB
Total Book Page : 1


Post a Comment

Previous Post Next Post
Increase website speed