Advanced Linux Commands for Developers

I have curated some of the most useful commands that Software Developers / DevOps Engineers often use.

I’m not covering the basic ones like — mkdir, rm, cat, cd, etc. Some medium to advanced commands…

grep

cat sample.txt | grep -i “TIM”

-i for case ignore

Or

grep -i “TIM” sample.txt
grep usage

In case you don’t know the file name, but just a text from a folder full of files, you might want to use this.

grep -irw -e "text to find"

Note: -n with grep will show the line numbers

find

find . -type f -name “*.csv” #type can be f — folder, d — directory# exclude name search during findfind . -type f -not -name "*.csv"

awk

awk can be used to split a line in a file and process (with delimiter)

awk command

sed

Is a stream editor, can be used to find / replace / insert / delete in a file.

netstat

netstat -tnpl | grep -i LISTEN

Will help to find the list of Listeners

lsof

lsof does a similar to netstat, but we can give specific port and check

lsof -t -i:<port_number> (list of open files)lsof -i tcp (list of files opened by network tcp)lsof -u <username> (list of files opened by user)lsof -I TCP:<port number>

cut

helps to split a text (line / string level manipulation)

cat <file> | cut -d (Delimiter) ‘<single_char>’ -f <nth element to cutting>

curl

used to make API calls to system (REST / SOAP)

curl -ik “http://localhost:5000/health”
curl usage

-k : used to bypass insecure network

kill (with SIGNALS)

The basics of kill is to simply kill a program running (given a pid).

Kill can also be used to send SIGNALS (OS Signals). Ex: HUP Signal

kill -s HUP <pid>

The above command becomes handy to reload a service without restarting. Can be used to reload, when a configuration has been changed / updated.

telnet

to check if a remote listener is active on a specific port

telnet <host_name> <port_no>
telnet usage

nslookup

Helpful in DNS resolution — especially to check if load balancers are working properly

nslookup <dns>
nslookup usage

Array Usage

car=(‘BMW’ ‘TOYOTA’ ‘HONDA’ ‘ROVER’)echo “${car[@]}” # print all values with spaceecho “${!car[@]}” # print only the indexesecho “${#car[@]}” # print the total number availableecho “${car[1]}” # print value based on index
Array usage

Looping through file (one line at a time)

for file in `cat sample.txt` do echo $file done 
Looping through files

Machine Stats

top — will give the running stats (machine usage)
top command usage
vmstat — will give the free, swap spaces and other details of CPU & Memory
vmstat command

Piping

Piping helps the output of first command to be used by next one — without using any variables (like a stream)

Commonly piped commands —  cat, grep, find, sort, awk

tar Commands

# creation of tar file
tar -cvf <tar_file_name> <list of files to be compressed>
# unzip tar files
tar -xvf <tar_file_name>
tar usage

sort

cat sample.txt | awk ‘{print $1}’ | sort
sort usage

reverse-search

CTRL + R — and start typing few chars, based on the history the previous commands will be displayed.

Use CTRL + R to move back and CTRL + F to move next

run a script in background

nohup /tmp/run.sh &

Firewall Commands

iptables -Fiptables -t nat -Fiptables -t nat -Xiptables -t mangle -Fiptables -t mangle -Xiptables -P INPUT ACCEPTiptables -P OUTPUT ACCEPTiptables -P FORWARD ACCEPT

Saving IP Table Rules

iptables-save > /tmp/firewall.rulesip6tables-save > /tmp/firewall6.rules

Command to kill a process (grep and kill) — single line command

ps -elf | grep -i <process> | awk ‘{print $2}’ | xargs kill -9
# if the process is running on a PORT
lsof -i -P -n | grep LISTEN | grep -i 8080 | awk '{print $2}' | xargs kill -9

I’ll try to keep this list updated whenever i find something interesting

-cheers

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The IPFS Cloud

SSH Into Your GitHub Account

Flutter — Dominating the complex UI.

Running Corda on GCP

Write a Program that Inputs Base and Height from the User &#124; C++

How Do Software Engineers Adapt to COVID-19 Outbreak?

A starting approach to solving coding interview questions.

Steps to create a base for mobile app development (Android or iOS)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vignesh Thirunavukkarasu

Vignesh Thirunavukkarasu

More from Medium

LVM in RHEL 8 Linux server

Five useful Linux commands

Linux on Windows…What?

Linux commands