introduction to linux filter command and its illustration

Reading Time: 3 minutes

What is Linux filter?

A filter is a program that takes plain text (stored in a file or generated by another program) as standard input, converts it to a meaningful format, and then returns it as standard output. Linux has several filters.

Some of the most commonly use filters are describe below.

1. cat : Display the text of the file line by line. 

Syntax:  

cat [path]

2. head: Shows the first n lines of the specified text file. If no number of lines is specifie, the first 10 lines are print by default.

Syntax:  

head [-number_of_lines_to_print] [path] 

3. Tail: Works the same as the head, but in reverse order. The only difference from Tail is that the line is return from bottom to top.

Syntax:  

tail [-number_of_lines_to_print] [path]

4. Sort: Sorts the rows alphabetically by default, but there are many options available to change the sorting mechanism. Check out the main page to see what you can do.

Syntax: 

sort [-options] [path]

5. uniq: Remove duplicate lines. uniq has the limitation that you can only remove consecutive duplicate rows (although you can fix this by using plumbing). Suppose you have the following date:

Syntax: 

uniq [options] [path]

6. wc: wc command gives the number of lines, words and characters in the data. 

Syntax: 

wc [-options] [path]

7. grep: grep is use to search a particular information from a text file. 

Syntax: 

grep [options] pattern [path]

8. tac: tac is the opposite of a cat and works the same. H. Instead of printing lines 1 through n, print lines n through line 1. This is the opposite of the cat command.

Syntax:  

tac [path] 

9. nl : nl is use to number the lines of our text data. 

Syntax: 

nl [-options] [path]

Written by 

Ashi Dubey is a Software Intern at Knoldus Inc Software. She has a keen interest toward learning new technologies. Her practice area is Devops. When not working, you will find her with a Book.