Linux Cheat Sheet 101

Linux,where a true freedom is !

Featured image

Linux is a kernel, on which lots of Operating systems like andriod, Debian, Arch are runnig.

The Linux “core” (called a kernel) was born in 1991 in Finland, and it has come a really long way from its humble beginnings. It went on to be the kernel of the GNU Operating System, creating the duo GNU/Linux.

What makes Linux special is,Distro !

Eg of linux distro are:-Ubuntu, Debian, kali, Parrot,openSUSE,Fedora

System

Commands Descriptions
uname Display the Linux information
uname-r Display the kernel information
utime Display how long the system has been running including the load average
hostname shows the system hostname
hostname-i display the IP address of the system
last reboot shows the system reboot history
date Display the current system date & time
timedatectl Query and change the system clock
cal Display the current calendar month and day
w Display currently logged in users in the system
whoami Display who you are logged in
finger username Display the information about the user

Hardware

Commands Descriptions
dmseg Display bootup messages
cat/proc/cpuinfo Displays more information about CPU eg. model, model name,cores,vendor id
cat/proc/meminfo Display the more information about hardware memory e.g total and free memory
lshw Display information about system's hardware configuration
lsblk Display the block device related information
free -m Display free and used memory in the system (-m flag indicates memory in MB )
lspci -tv Display PCI devices in a tree-like diagram
lsusb -tv Display USB devices in a tree-like diagram
dmidecode Display hardware information from the BIOS
hdparm -i /dev/xda Display information about the disk data
hdparm -tT/dev/xda Conducts a read speed test on device xda
badblocks -s/dev/xda Test for unreadable blocks on disk

User

Commands Descriptions
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 into the System
groupadd "admin" Adds the group "admin"
adduser"Shubham" Adds user Shubham
userdel"Sam" Deletes user Sam
usermod used for changing/modifying user information

File commands

Commands Descriptions
ls -al List files both regular and hidden along with their permission
pwd Display the path of the current directory
mkdir <directory_name> Creates a directory
rm <file_name> Delete file
rm -r <directory_name> Delete directory recursively
rm -f <file_name> Forcefully remove file
rm -rf <directory_name> Forcefully remove the directory
cp file1 file2 copy file1 to file2
cp -r dir1 dir2 copy dir1 to dir2 ,creates dir2 if it doesn't exits
mv file1 file2 Rename source to Destination/move source to directory
ln -s /path/to/file-name link name Creates symbolic link to the file-name
touch file Creates/ Update file
cat > file Place standard input into filel
more file Output contents of file
head file Output first 10 lines of file
tail file Output last 10 lines of file
tail -f file Output contents of file as it grows starting with the last 10 lines
gpg -c file Encrypt file
gpg file.gpg Decrypt file
wc print the number of bytes,words,and lines in files
xargs Execute command lines from standard input

File Permission Related

Commands Descriptions
chmod octal < file_name> Change the permission of the file to local
Eg: -
chmod 777 /data/test.c Set rwx permission for owner,group,world
chmod 755/data/test.c Set rws permission for the owner, rx for group and world
chmod 766/data/test.c Sets rwx for the owner,rw for the group and everyone
chown owner user-file Changes the ownership of the file
chown owner-user:owner-group
< file_name>
change owner and group owner of the file
chown owner-user:owner-group
-directory
change owner and group owner of the directory

Process Related

Commands Descriptions
ps Display the current active processes
ps aux | grep 'telnet' Searches for the id of the process 'telnet'
pmap Display memory map of the process
top Displays all running processes
kill pid Terminates process with a given pid
killall proc kills/Terminates all processes named proc
pkill process-name Sends a signal to a process with its a name
bg Resume suspended jobs in the background
fg Brings suspended jobs to the foreground
fg n Brings job n to the foreground
lsof Lists files that are open by processes
renic 19 PID Makes a process run with very low priority
pregp firefox find Firefox process ID
pstree Visualizing processess in tree model

Network Related

Commands Descriptions
ip addr show Displays IP addresses and all the network interfaces
ip address add 192.1.20
dev eth0
Set Ip address
ifconfig Displays Ip addresses of all network interfaces
ping host ping command sends an ICMP echo request to establish a connection to
server/Pc
whois domain Retrievs more information about a domain name
dig domain Retrievs DNS infromation about the domain
dig-x host Performs reverse lookup on a domain
host google.com perfroms an Ip lookup for the domain name
hostname-i Display all local Ip address
wget <file_name> Downloads a file from an online source
netstat-pnltu Displays all active listening port

Compression/Archives

Commands Descriptions
tar -cf home.tar home creates archive file called 'home.tar' from file 'home'
tar -Xf files.tar Extracct archive file 'files.tar'
tar -ZCVf home.tar.gz
Source-folder
Creates gzipped tar archive file from source folder
gzip file Compression a file with .gz extension

Install packages

Commands Descriptions
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

Install Source (Compilation)

./ configure
make
make install

Search

Commands Descriptions
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

Login

Commands Descriptions
ssh user@host Securely connect to host as user
ssh -p <port_number>
user@host
Securely connect to host using a specified port
ssh host Securely connect to the system via SSH default port 22
telnet host Connect to host via telnet default port 23

File Transfer

Commands Descriptions
scp file1.txt server2/tmp Securely copy file1.txt to server2 in /tmp diretory
rsync -a/home/apps /backup Synchronize contents in /home/apps directory with directory

Disk usages

Commands Descriptions
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 points for all filesystems
mount device-path
mount-point
Mount a device

Directory Traverse

Commands Descriptions
cd .. Move up one level in the directory tree structure
cd change directory to the $HOME directory
cd /test Change directory to the /test directory