Skip to content

Instantly share code, notes, and snippets.

@sidanand67
Last active July 1, 2022 07:08
Show Gist options
  • Save sidanand67/1574e9ada832b23270062f800d13522d to your computer and use it in GitHub Desktop.
Save sidanand67/1574e9ada832b23270062f800d13522d to your computer and use it in GitHub Desktop.
Sidharth_CLI_Drills_II
# CLI Drill 2
# ===== Pipes =====
# Question 1
echo "Downloading file..."
wget https://raw.githubusercontent.com/bobdeng/owlreader/master/ERead/assets/books/Harry%20Potter%20and%20the%20Goblet%20of%20Fire.txt 2> log.txt -O book.txt
# Question 2
echo -e "\n\nTop 3 lines"
head -n 3 book.txt
# Question 3
echo -e "\n\nBottom 10 lines"
tail -n 10 book.txt
# Question 4
# word: Harry
echo -e "\n\nHarry Word Count..."
grep -io harry book.txt | wc -l
# word: Ron
echo -e "\n\nRon Word Count..."
grep -io ron book.txt | wc -l
# word: Hermione
echo -e "\n\nHermione Word Count..."
grep -io hermione book.txt | wc -l
# word: Dumbledore
echo -e "\n\nDumbledore Word Count..."
grep -io dumbledore book.txt | wc -l
# Question 5
echo -e "\n\nLines in the range 100-200..."
awk 'FNR==100,FNR==200 {print FNR ":" $0}' book.txt
# Question 6
echo -e "\n\nUnique words..."
tr ' ' '\n' < book.txt | sort | uniq | wc -l
# ===== Process =====
# Question 1
ps aux | grep brave
# Question 2
pkill -9 brave
# Question 3
ps aux --sort -pcpu | head -n 4
# Question 4
ps aux --sort -pmem | head -n 4
# Question 5
echo -e "\n\nStarting server on 8000..."
gnome-terminal -- python3 -m http.server 8000
# Question 6
pkill -9 python
# Question 7
echo -e "\n\nStarting server on 90"
sudo gnome-terminal -- python3 -m http.server 90
# Question 8
sudo lsof -i
# Question 9
sudo lsof -i:5432 | grep LISTEN
# ===== Managing Software =====
# Question 1
sudo apt install nginx vim htop
# Question 2
sudo apt remove nginx
# ===== Misc =====
# Question 1
ip route | grep default
# Question 2
nslookup google.com
# Question 3
ping -c1 8.8.8.8
# Question 4
# node command
which node
# code command
which code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment