The terminal is the heart of Linux, a place where commands hold the power to transform complex tasks into simple actions. Whether you’re organizing files, monitoring system performance, or automating processes, Linux commands are your ultimate toolkit. In this blog, we’ll guide you step by step through the most essential and practical commands to help you harness the full potential of Linux.
cd → change directory
pwd → Present working directory
id → logged in user information
sudo -i → switch to root user (/root)
mkdir → To create a new directory
rmdir → To remove folder
rmdir folder-* → To delete all folders
ls → listing all files and directories in current location
exit → logged out from current user
sudo su → switch to root user with ubuntu home directory (/home/ubuntu)
touch → To create a new empty file
cat → To check file content
vim → To edit or create a new file
# vim filename
Shift + i
Insert the data
# esc →> :wq:set nu → It will give temp numbers to each line in vim editor
rm -rf → To remover file
cd / → top level directory in linux
ls -a → list all files (hidden & non hidden)
ls -l → long listing
date → To check the timing of VM
ls -lrt →
l-> long format
r -› reverse order
t →> sort by time
ls -lrtah → It will give hidden files(a) in human reading format(h)
clear → terminal clear
cp → copy file from one location to another location cp folder1/myfile /folder2
mv → to move file from one location to another mv folder1/myfile folder2/
mkdir -p folder-1/folder-2/folder-3 → create folder under another folder
cd . → same directory
cd .. → goes back to one folder
cd ../.. → goes back to two folders
cd ~ → /root
cd → /root
echo "welcome to Vaishali’s blog" → prints message on console
Here different way to print on console
• echo class7 class9
• echo welcome to Vaishali’s blog
• echo 'welcome to Vaishali’s blog'
• echo '''welcome to Vaishali’s blog'''
echo "I am adding 1 line" › myfile → it will add data to myfile but it will delete previous data
echo "I am adding 2nd line" >> myfile → It will add data to myfile without deleting previous data
cd var/logs —head auth.log → It will display top 10 logs of auth file
tail auth.log → It will display bottom 10 logs of auth file
tail -15 auth.log → It will gave bottom/recent 15 logs from auth file.
head -n 7 filename | tail -n 4 → from number 1 to 10 you need print middle numbers 4,5,6,7 use this command.
Here first print head 7 is 1,2,3,4,5,6,7 then tail 4 will get last 4 numbers 4,5,6,7 .
cat auth.log | grep “sudo” → grep is used to search particular word.
grep will filter sudo in auth file and displays.
cat auth.log | grep -i “Status” → -i will ignore case sensitivity of letters.
cat auth.log | grep -i “Status” | grep “linux” → you can use more than one grep to find particular line
more auth.log → just like load more of Facebook. Press ctrl+c to get out
less auth.log → it shows content in less.
Press q to get out
man → it will give detail description of commands manually.
man ls> ls.txt — cat ls.txt | grep “lrt” → it will apply filter on man commands
ifconfig → to check ip address on linux
hostname -i → it is also used to check ip address on linux
traceroute www.google.com → It gives domain’s output logs
tracepath www.google.com → It also give domains output logs
ping www.google.com → to check response from website. It works on icmp port 1.
ping -c 5 www.google.com → to check 5response from website.
netstat -a → to get port information
dig www.google.com → to get domain’s information
nslookup www.google.com → it is mostly used to get domain’s information
apt(Advanced Package Tool) → it is use to install package on Linux. apt install nginx
ps -aux | grep nginx → to get active services
ps -aux :
ps - process status
a - All process
u - With user
X - daemons/executeapt
update -y → to update your local repo
apt list → List of all installed packages
apt install nginx → to install packages
apt show nginx → to get all information of package
apt info nginx → it also used to get all information about package
apt remove nginx → to remove or delete package from local repo
systemctl status nginx → To check status of package like active or inactive
systemctl stop nginx → To stop service
systemctl start nginx → To start service
yum install nginx(Amazon Linux) → To install package on amazon linux
cd /usr/share/nginx/html/ → html file location on Amazon linux server
cd/var/www/html → html file location on ubuntu server
cd /etc/nginx/ → It has nginx configuration file
useradd Ram
passwd Ram- give password → To add new user.
When we add new user an individual group is created for that user. Mostly used
adduser Ram → it is also used to create user but in small letters only ie ram.
For capital Ram it gives error. Less used
cat /etc/passwd → To check added user info
groupadd Devops → To add new group
cat /etc/group → To check user information
chmod -g 1003 Ram → adding user to group. 1003 is group id
su Ram → swich user to Ram
groups Ram → to check groups of user
Ram: x: 1001:1003::/home/Ram:/bin/sh → here 1001 is userId and 1003 is group Id
cat /etc/passwd | grep “1003” → to check users associated with 1003 id
userdel Ram → to delete user
groupdel Devops → to delete group
Mohan: x: 1001:1003::/ home/Mohan:/bin/sh
awk -F: '$4 == "1003" {print $1}' →
$1 will print first value
It will get output as Mohan
**find . -name “*.txt”**→ to fina txt file in current directory
locate file1 → to find file
df -h → to get disk space in human readable format
du -h → to get disk usage in human readable format
kill -9 nginx → it will kill service forcefully
wget → download file from internet
cat /etc/os-release → get os information
history → to get command history
cut -d ' ' -f2 vaishali → it will delimit data from 2nd field
cut -b 2 vaishali -> it will give 2nd alphabet
echo class7 class9 | sed 's/class/jtp/g'. output→ jtp7/jtp9
Good morning
Welcome to Vaishali’s blog
We are learning AWS/Devops Good
bye take care
cat file | sed 's/Good/Bad/g' →
Output : Bad morning
Welcome to Vaishali’s blog Bad
We are learning AWS/Devops
bye take care
sed -i 's/Good/Bad/g' file → -i will change in original file
sed '1s/Bad/Good/' file → It won’t change 1st Good other will get change output -> Good Morning
welcome to Vaishali’s blog Bad
we are learning AWS/Devops
bye take care, Bad night
vim test — cat test | grep k8s — sed -i 's/k8s/Ram/' test — cat test | grep Ram —> It will replace k8s with Ram
cat file —Bad morning
Welcome to Vaishali’s blog Bad
We are learning AWS/Devops
bye take care, Good night
wc file→it will give count of file. 4 lines, 16 words, 92 letters
Output : 4 16 92 file
wc -1 file → count of lines
wc -w file → count of words
top -n 1 | grep "load average" | cut -d " " -f11-18 —-> load average: 0.01, 0.04, 0.01 → it will give load average from top command.
We can customise the desired output using this command
awk '{print $13' info.txt → it will print first row in the table
awk '{print $03' info.txt → print table as it is
awk '{print $NF}' info.txt → print last row in the table
awk '{print $NF}' info.txt | head -n 2 | tail -n 1→ print first value of last row
awk '{print $NF}' info.txt | tail -n 1 → print last value of last row
awk '{print 52}' info.txt l tail -n 2 | head -n 1 → print second last value from second row
init 6 → restart machine ec2
init 0 → stop machine ec2
scp -i "batch-24.pem" anyfile ubuntu@ec2-54-174-136-191.compute-1.amazonaws. com: / tmp/ …anyfile → it will secure copy file from local to server
chown ubuntu folder-1/ → make ubuntu as a owner of folder-1
chgrp ubuntu folder-1/ → make ubuntu as a group of folder-1
ln myfile hardlink_myfile → it will create exact copy of myfile.
if you make changes in original file, it will transfer automatically to the hardlink.
even if original file is deleted, hardlink copy will not delete
- ln -s myfile softlink_myfile -> it will create exact copy of myfile.
if you make changes in original file, it will transfer automatically to the softlink . Softlink will get delete when original file gets deleted
tar -czvf file1.tar.gz file1 → making archive file of file1
tar -xvf folder.tar.gz → unarchive folder
c: Creates Archive
x : Extract the archive
f: creates archive with given filename
t : displays or lists files in archived file
u : archives and adds to an existing archive file
v : Displays Verbose Information
A : Concatenates the archive files
z: zip, tells tar command that creates tar file using gzip
j: filter archive tar file using tbzip
W: Verify a archive file
r: update or add file or directory in already existed tar file