Skip to content

Instantly share code, notes, and snippets.

@shriagnish2021
Last active May 17, 2021 18:27
Show Gist options
  • Save shriagnish2021/0213f691b72c64624a93cfb962d600de to your computer and use it in GitHub Desktop.
Save shriagnish2021/0213f691b72c64624a93cfb962d600de to your computer and use it in GitHub Desktop.
SHRI_CLI_Drills_II
Pipes
1.Download the contents of "Harry Potter and the Goblet of fire" using the command line from here
wget https://raw.githubusercontent.com/bobdeng/owlreader/master/ERead/assets/books/Harry%20Potter%20and%20the%20Goblet%20of%20Fire.txt
2.Print the first three lines in the book
head -n 3 'Harry Potter and the Goblet of Fire.txt'
3.Print the last 10 lines in the book
tail -n 10 'Harry Potter and the Goblet of Fire.txt'
4.How many times do the following words occur in the book?
Harry
Ron
Hermione
Dumbledore
grep -i -o Harry 'Harry Potter and the Goblet of Fire.txt' | wc -l
3172
grep -i -o Ron 'Harry Potter and the Goblet of Fire.txt' | wc -l
1358
grep -i -o Hermione 'Harry Potter and the Goblet of Fire.txt' | wc -l
872
grep -i -o Dumbledore 'Harry Potter and the Goblet of Fire.txt' | wc -l
596
5.Print lines from 100 through 200 in the book
head -n 200 'Harry Potter and the Goblet of Fire.txt' | tail -n 101
6.How many unique words are present in the book?
tr -c "a-zA-Z0-9'" "\n" < 'Harry Potter and the Goblet of Fire.txt' | tr "[:upper:]" "[:lower:]" | sort | uniq | wc -l
10648
Processes
1.List your browser's process ids (pid) and parent process ids(ppid)
ps x xao pid,ppid,command | grep chrome
2.Stop the browser application from the command line
pkill chrome
3.List the top 3 processes by CPU usage.
ps -A --sort=-pcpu | head -n 4
4.List the top 3 processes by memory usage
ps -A --sort=-%mem | head -n 4
5.Start a Python HTTP server on port 8000
python -m SimpleHTTPServer 8000
6.Open another tab. Stop the process you started in the previous step
sudo kill -9 $(sudo lsof -t -i:8000)
7.Start a Python HTTP server on port 90
sudo python -m SimpleHTTPServer 90
8.Display all active connections and the corresponding TCP / UDP ports.
sudo netstat -tun
9.Find the pid of the process that is listening on port 5432
lsof -t -i:5432
Managing Software
1.Install htop, vim and nginx
sudo apt-get install htop
sudo apt-get install vim
sudo apt-get install nginx
2.Uninstall nginx
sudo apt-get remove nginx
Miss
1.What's your local IP address?
ifconfig
2.Find the IP address of google.com
nslookup google.com
3.How to check if Internet is working using CLI?
ping google.com
and then press control+c
If it runs without giving any error, then there is internet connection.
if I get an error there is no internet connection
or
ifconfig
In the result of this command,we can get to know if there is a wireless internet connction or not by checking if the IP provided by ISP exists or not.
4.Where is the node command located? What about code?
$ which node
/usr/bin/node
$ which code
/usr/bin/code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment