Skip to content

Instantly share code, notes, and snippets.

@Wadkar07
Last active February 9, 2023 09:36
Show Gist options
  • Save Wadkar07/5673bbd3ae22b02bd403625d440816da to your computer and use it in GitHub Desktop.
Save Wadkar07/5673bbd3ae22b02bd403625d440816da to your computer and use it in GitHub Desktop.
Command_drill_II
#######
#Pipes#
#######
#Download the contents of "Harry Potter and the Goblet of fire" using the command line
wget https://raw.githubusercontent.com/bobdeng/owlreader/master/ERead/assets/books/Harry%20Potter%20and%20the%20Goblet%20of%20Fire.txt
#Print the first three lines in the book
#using awk
cat "Harry Potter and the Goblet of Fire.txt" | awk 'FNR==1,FNR==3'
#using head
cat "Harry Potter and the Goblet of Fire.txt" | head -3
#Print the last 10 lines in the book
cat "Harry Potter and the Goblet of Fire.txt" | tail -10
#How many times do the following words occur in the book?
#Harry
cat "Harry Potter and the Goblet of Fire.txt" | grep -c Harry #2591
#Ron
cat "Harry Potter and the Goblet of Fire.txt" | grep -c Ron #947
#Hermione
cat "Harry Potter and the Goblet of Fire.txt" | grep -c Hermione #822
#Dumbledore
cat "Harry Potter and the Goblet of Fire.txt" | grep -c Dumbledore #507
#Print lines from 100 through 200 in the book
cat "Harry Potter and the Goblet of Fire.txt" | awk 'FNR==100,FNR==200'
#How many unique words are present in the book?
cat "Harry Potter and the Goblet of Fire.txt" | awk '{ for(freq = 1; freq <= NF; freq++) {words[$freq]++} } END { for(freq in words) if(words[freq] == 1) { uwc++ } print uwc }'
#12540
###################
# Processes, ports#
###################
#List your browser's process ids (pid) and parent process ids(ppid)
pgrep brave
#52071 (pid)
#52081 (pid)
#52091 (pid)
#52092 (pid)
#52094 (pid)
#52117 (pid)
#52118 (pid)
#52147 (pid)
#52165 (pid)
#52296 (pid)
#52452 (pid)
#52544 (pid)
#57738 (pid)
#92612 (pid)
#92681 (pid)
#95526 (pid)
#98454 (pid)
#99258 (pid)
#99531 (ppid)
#Stop the browser application from the command line
pkill brave
#List the top 3 processes by CPU usage.
ps -eo pid,ppid,comm,%mem,%cpu --sort=-%cpu | head -4
# top 4 are taken because it also includes coloumn name i.e pid, ppid, command, memory used, cpu usage
#Start a Python HTTP server on port 8000
python -m http.server 8000
#Open another tab. Stop the process you started in the previous step
kill $(ps -e | grep python | awk '{print $1}')
#Start a Python HTTP server on port 90
sudo python -m http.server 90
# Display all active connections and the corresponding TCP / UDP ports.
netstat -atu
Find the pid of the process that is listening on port 5432
netstat -ltnup | grep ':5432'
###################
#Managing software#
###################
#Install htop
sudo apt install htop
#Install vim
sudo apt install vim
#Install nginx
sudo apt install nginx
#Uninstall nginx
sudo apt remove nginx
##################
# Mmiscellaneous #
##################
#What's your local IP address?
hostname -I
#Find the IP address of google.com
host google.com
#How to check if Internet is working using CLI?
ping -c 2 google.com
#Where is the node command located?
which node
#What about code?
which code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment