Basic Commands:
Beginners:
Cal – Displays calendar information
cd – Changes directory
date – Displays current date
groupadd test – Creates group test
hostname – Displays hostname of a system
hostname -I – Displays ip address of a hostname
id – Shows the user and group ids of current user
last reboot – Displays the reboot information
ls – lists the file names
mount – Shows mounted file systems
uptime – Displays system running time
uname -r – Shows kernel release information
uname -a Shows system information
useradd -c “GK” +m Gokhan – Creates Gokhan account with comment Gk
userdel Gokhan – Deletes the account Gokhan
usermod -aG Networker Gokhan – Add account Gokhan to the networker group
sudo passwd <username>
who – Shows who logged onto the system
whoami – Shows who logged on to the system
w – Shows who logged on the system and what they do
ls -i
od -c filename – Shows the inode data at the screen
File Management:
chown user – Changes ownership of a file / directory
chown user:group filename – Changes user and group for a file or directory
File Permission r(read) : 4 , w(write) 2, x(execute) 1, – ( No permission )
File Owner – Owner/group/everyone
File Permission Examples:
777
Owner, Group, User has rwx permission
744
Owner has rwx, Group and User have r permission only
755
Owner has rwx, Group and User have r and x permission only
Network Commands:
arp – Displays the ARP table of the device
arpwatch – Displays ethernet activity and ethernet ip pairing
dhclient – Used to analyze the clients ip address, subnet mask, gateway, dns server
dig – Used for simple dns lookup
dstat – Collects and shows system resources
ethtool – Used to check the setting of NIC
ftp – Used for file transfer
host – Used for IP name matchings
hping3 – Used for packet analyze
ifstat – Used to monitor network interface statistics
ip addr – Used to check network interfaces and routing activities
iptables – Used for ip packet filtering
iftop – Displays the current bandwidth usage
ifup / ifdown – Used to enable or disable interfaces
iwconfig – Used to configure wireless interfaces
netstat – To check network interfaces
nload – Used as bandwidth monitoring tool
nmap – Used for security audits
nslookup – Used for dns query
ping – Used to check reachability
route – displays the IP routing table
scp – Secured file transfer
sftp – Secured file transfer
ss – Gives detailed information about sockets
ssh – Used for secured connection
tshark – Analyzing and capturing
tcpdump – Used for analyzing and capturing
telnet – Used for classical unsecure connection
tracepath – Used for path tracking
w – Used to check current system activity
wget – Used to download the contents of web servers
whois – Checks the whois database and return with IP and domain info
Disk Usage Commands:
df – Shows free hard disk space on system
df -h – Shows free and used space on mounted file systems
df -i – Shows free and used inodes on mounted file systems
du -ah – Shows disk usage for all files and directories in a readable format
du -sh – Shows total disk usage off the current directory
fdisk -l – Shows free and used inodes on mounted file systems
free -h – Shows free and used memory
free – Shows free RAM on system
findmnt – Shows target mount point for all file system
mount /xyz /abc – Mounts a devices in /xyz to /abc
fstab – Configuration table to maintain mount and unmount of the file system.
fsck – File system consistency check, checks the root file system during boot time, Ex: $fsck /dev/sdb
File Transfer Commands:
scp source address destination address
Ex(Copies the files from linux to windows, at windows prompt): scp sureshd@192.168.29.19:/local/mnt/workspace/sureshd/project1/test.tar.zst .
scp -r server:/var/www /tmp
Secure copy of all files and directories recursively from server to the current systems /tmp folder
rsync -a /home /backups/
Synchronize /home to /backups
rsync -avz /home server:/backups/
Synchronizes files directories between the local and remote system with compression enabled
Hardware Commands:
badblocks -s /dev/sda – Tests for unreadable blocks on disk sda
cat /proc/cpuinfo – Displays CPU information
cat /proc/meminfo – Displays memory information
dmesg – Displays messages in kernel ring buffer
dmidecode – Displays DMI/SMIBIOS from BIOS
lspci -tv – Displays PCI devices
lsusb -tv -Displays USB devices
hdparam -l /dev/sda – Displays info about disk sda
hdparam -tT /dev/sda – Performs a read speed test on disk sda
Search Commands:
grep x file – Searches for x in file
find /test/ -name aaa* finds files starting with aaa in test
find /dir/ -user Gokhan – finds files owned by Gokhan in dir
find /dir/ -mmin 10 – finds files modified lessthan 10 minutes ago
find /home -size +500M – finds file larges than 500MB in /home
find [/folder/location] -name[x] – finds file names starting with character x
locate abc – finds the location of abc quickly
whereis aaa – locates the binary, source, and manual page of aa
Compress and Decompress Commands:
gzip abc – Compresses abc file using gzip
gzip -d xyz.gz – Extracts xyz.gz with gzip facility
tar -czvf archive.tar.gz /home – Compresses a full directory with all subdirectories
tar -xzvf – Extracts a gzip compressed tar file
Process Commands:
bg – Lists and resumes stopped jobs in bg
fg – Brings the most recent background job to foreground
fg x – Brings job x to the foreground
htop – Interactive process viewer
kill pid – Kills process with process ID of pid
killall abc – Kills all processes named abc
lsof -Lists files opened by running processes
nice – Starts a process with a given priority
ps – Displays currently running processes
ps PID – Gives the status fo a particular process
pidof – Gives the process ID of a process
ps -ef | grep xyz – Displays process information for xyz
pkill xyz – Kills process with name xyz
program & – Starts program in the background
renice – Changes priority of a running process
pstree – Processes in a tree-like diagram
psmap – A memory usage map of processes
top – Displays and manages top processes
lsof -i port:12128 – To search the the status of process running at the port 12128
File Management:
cat abc – Opens the file abc in a read mode
cp aaa bbb – Copies the files from aaa to bbb
file abc – Gets type of abc
get abc – Downloads file abc from remote to local device
gpg -c abc – Encrypts the file abc
gpg abc – Decrypts the file abc
head abc – Displays first 10 lines of abc file
ls -l – Shows the file type and access permission
mv aaa bbb – Moves the file from aaa to bbb
pwd – Shows present directory
put abc – Uploads file abc from local to remote device
rm xyz – Deletes the file xyz
rm -r /xyz – Deletes directory /xyz and its contents recursively
rm -f abc – Forcefully deletes abc file without confirmation
tail abc – Displays the last 10 lines of abc file
Install Commands:
sudo install abc – Installs abc package
sudo info abc – Displays description and summary info about the abc package
rpm -i abc.rpm Installs package from local file names abc.rpm
yum remove abc – Remove/Uninstall abc package
yum list installedl – Lists all installed packages with yum
yum search [keyword] – Finds a package by a related keyword
SSH Keys:
ssh-keygen -R
ssh-keygen -t ed25519 -C “email id”
Some more
lsblk -f
sudo du -h –max-depth=1 .
blkid
df -T
tmux Sessions:
$ tmux new-session :Start a new session
$ tmux new-session -A -s mysession :Start a new session or attach to an existing session named mysession
$ tmux new -s mysession :Start a new session with the name mysession
$ tmux kill-session -t mysession :kill/delete session mysession
$ tmux kill-session -a :Kill/Delete all sessions but the current
Ctrl + b $ Rename a session
Ctrl + b d Detach from session
$ tmux list-sessions :Show all sessions
(or) Ctrl + b s
$ tmux attach-session :Attach to last session
$ tmux attach-session -t mysession :Attach to a session with the name mysession
Ctrl + b w :Session and Window Preview
Ctrl + b ( :Move to previous session
Ctrl + b ) :Move to next session
tmux Windows
$ tmux new -s mysession -n mywindow start a new session with the name mysession and window mywindow
(or) Ctrl + b c
Ctrl + b , :Rename current window
Ctrl + b & :Close the current window
Ctrl + b w :List windows
Ctrl + b p :Previous window
Ctrl + b n :Next window
Ctrl + b 0 ..9 :Switch/Select window by number
Ctrl + b I :Toggle last active window
tmux Panes:
Ctrl + b ; Toggle last active pane
Ctrl + b % Split the current pane with a vertical line
Ctrl + b ” Split the current pane with a horizontal line
Ctrl + b { Move the current pane left
Ctrl + b } Move the current pane right
Ctrl + b Up Arrow
Ctrl + b Down Arrow
Ctrl + b Right Arrow
Ctrl + b Left Arrow Switch to pane to the directions
Ctrl + b o Switch to next pane
Ctrl + b q Show pane numbers
Ctrl + b q 0…9 Switch/select the pane by number
Ctrl + b z Toggle pane zoom
Ctrl + b ! Convert pane into a window
Ctrl + b x Close current pane
Dockers
Images: Build an Image from a Docker file
docker build -t <Image_Name>
List local Images: docker images
Delete an Image: docker rmi <Image_Name>
Remove all unused Images: docker image prune
Create and run a container from an image, with a custom name:
docker run –name <Container_name> <Image_name>
Run a container with and publish a containers ports to the host:
docker run -p : <host_port>
Run a container in the background
docker run -d <Image_Name>
Start or Stop an existing container:
docker start | stop (or ) <Container_Name> ( or <Container_Id> )
Remove a stopped container:
docker rm <Container_Name>
Open a shall inside a running container:
docker exec -it <Container_Name> sh
Fetch and follow the logs of a container:
docker logs -f <Container_Name>
To Inspect a running container:
docker inspect <Container_Name> (or <Container_Id> )
To list currently running containers:
docker ps
List all docker containers(running and stop):
docker ps –all
View resources usage stats:
docker containers stats


