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.
Head Command
Tail Command
Less Command
More Command
Sort Command
Grep Command
Locate Command
Find Command
Head Command :
By default, it prints the first 10 lines If we need to print the more lines, then we need to specify the number of lines help of “-n” keyword.
head filename
head -n filename
Tail Command :
By default, it prints the last 10 lines If we need to print the more lines, then we need to specify the number of lines help of “-n” keyword.
tail filename
tail -n filename
Less Command :
Less command is a Linux utility that can be used to read the contents of a text file one page(one screen) at a time. It has faster access because if file is large it doesn’t access the complete file, but accesses it page by page.
less filename
Note : using "q" exit from file.
More Command :
the more command displays the first section of the file. By pressing the “ENTER” key, you can scroll line by line, all the way to the bottom of the file.
more filename
Sort Command :
SORT command in Linux is used to arrange the data in a specific order according to the option used. It helps in sorting the data in the file line by line.
Grep Command :
Grep command in Linux is the short form of ‘global search for the regular expression’. The grep command is a filter that is used to search for lines matching a specified pattern and print the matching lines to standard output.
The grep command supports a number of options for additional controls on the matching:
-i: performs a case-insensitive search.
-n: displays the lines containing the pattern along with the line numbers.
-v: displays the lines not containing the specified pattern.
-c: displays the count of the matching patterns.
-l: displays the match of file names
-An: displays the match after n lines
-Bn: displays the match before n lines
Locate Command :
The locate command finds files in Linux using the file name. locate is used for obtaining instantaneous results, and it is an essential utility when speed is a priority.
Find Command :
The find command is a powerful utility to search for files or directories.
The search can be based on different criteria, and the matching files can be run through defined actions. This command recursively descends the file hierarchy for each specified pathname.
Liked This Article?
Conclusion
I’m sure that this tutorial would have helped you to get a good understanding of what is Filter Commands