Day 3: Advanced Linux
Table of contents
Vim File Editor
It is the widely used file editor of Linux OS that helps you to insert text in a file and save it for later use. It is the improved version of Vi editor.
$vim file: open a file named 'file' in vim editor
Once the vim editor will open, press 'i' for insert mode.
Once the file is in insert mode, you can write in the text you want to save. when you finish writing in the file and want it to save and exit the vim editor, press esc and write ':wq'.
Now you are out of the editor.
Advanced Commands
$cat fruits.txt: display the content of the file
$echo -e "pineapple" >> fruits.txt: append the text 'pineapple' at the end of the file
$head -3 fruits.txt: display the first 3 fruits in the fruits.txt file
$tac: reverse of cat will display the output in reverse order
$head -3 fruits.txt | tac: display the first 3 fruits in the file and pass on the output to next command after '|'. Then 'tac' will reverse the order of those 3 fruits.
$tail -3 fruits.txt: display the last 3 fruits in the fruits.txt file
$sort: sort the output in alphabetical order
$echo -e "Red\npink\nOrange\nYellow\nWhite" > colors.txt : Enter colors in each line of file colors.txt
Echo allows users to display lines of text or strings that are passed as arguments. '\n' denotes the new line from where it is used. '>' used to send output in the file after it.
$echo -e "Blue\n$(cat colors.txt)" > colors.txt : Enter the blue color in the beginning of file colors.txt
$comm -12 <(sort colors.txt) < (sort fruits.txt) : Display the common of both files
Comm command is used to compare two files and find the common, unique and different values. Here '-12' denotes the column of the files.
$wc colors.txt fruits.txt: Count the number of lines, words, and characters in both files
Here we hands on the advanced commands in Linux. Hope you find it helpful. In the next blog we will learn Shell scripting. So stay tuned.
Thanks for reading my blog. Hope you find it interesting and helpful. - Neha Bhardwaj
Subscribe to my newsletter
Read articles from Neha Bhardwaj directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by