Introduction
A lot of people find Linux more challenging as an operating system especially when they are coming from the comfort of using Windows or macOS. Here, I'm presenting you the basic but very important Linux commands to give you an in-depth knowledge of how to use your Linux terminal.
Text Processing Tools
In this article, we will review a number of command line tools that act as filters in Linux. A filter is a program that reads standard input, performs an operation upon it and writes the results to standard output.
For this reason, it can be used to process information in powerful ways such as restructuring output to generate useful reports, modifying text in files and many other system administration tasks.
With that said, below are some of the useful file or text filters in Linux.
Command 1: less
This is used to display the text in pagewise format.
less filename
Command 2: head
This will display the top 10 lines of a file.
head filename
To display top 3 lines of a file.
head -3 filename
Command 3: tail
This will display the last 10 lines of a file.
tail filename
To display the last 4 lines of a file.
tail -4 filename
Command 4: wc
This is used to find the number of lines, words and characters in a file.
wc filename
To find only the no of lines.
wc -l filename
To find only the number of words.
wc -w filename
To find only the number of characters.
wc -c filename
Command 5: sort
Used for sorting the content of a file. By default it performs an alphabetical sort.
sort filename
To perform a numeric sort.
sort -n filename
To perform a reverse numeric sort.
sort -nr filename
Command 6: grep(globally search for a regular expression and print it)
This is used for searching for a sequence of characters in a file. grep will display all the lines where the given string is present.
To search for a word called intelliq.
grep intelliq filename
To search for intelliq ignoring its case.
grep -i intelliq filename
To search for a word intelliq and also display the line numbers.
grep -n intelliq filename
To search for all the lines where the word intelliq is not present.
grep -v intelliq filename
Command 7: cut
This is used to capture the data in column fashion.
To pick 1st and 7th column from /etc/passwd file
cut -d ":" -f 1,7 /etc/passwd
Summary
The key is to use these commands more often in your daily activities. Once you master these commands, it becomes your best ally, and you won’t regret choosing it as your daily driver.
One of the remarkable things about Linux is that even if you’re an experienced user, you’ll never stop learning to be more productive using it.
There are a lot more helpful Linux commands. If we’ve left something out, please share your favorite Linux commands in the comments below!
Happy Learning!