File filters commands in Linux

Linux distributions come with various powerful file filtering commands. You can get fast results just with the help of some simple commands.

Different file filter commands used in Linux are as follows: 

1) wc: 
To see the no of characters in a file - $wc - c <file name>
To see the no of words in a file - $wc -w <file name>
To see the no of lines in a file - $wc -l <file name>
To see the no of lines, words, characters at a time - $wc <file name>

2) Pipe ( | ) :
We can carry out piping between two commands. Here, the standard output of first command is taken as the standard input for the second command.
<Command1> | <command2>   e.g. $ll | wc

3) head :
To see the top 10 lines of a file - $head <file name>
To see the top 5 lines of a file - $head -5 <file name>  

4) tail :
To see last 10 lines of a file - $tail < file name>
To see last 20 lines of a file - $tail -20 <file name> 

5) more
To see the contents of a file in the form of page views - $more <file name>
e.g . $more f1.txt
                
6) sed : 
It is used to cut the information horizontally.
To see the first line in file sun, 
$sed -n 1p sun
To see 3 to 5 lines
$sed -n '3,5p' sun

7) grep
To search a pattern of word in a file, grep file is used.
syntax $grep < word name> < file name>
$grep hi file_1  
To search multiple words in a file
$grep -E ' word1|word2|word3|' <file name>
e.g. $grep -E 'hi|beyond|good' file_1

8) sort
This command is used to sort the file .
$sort  <file name>
e.g.: $sort file_1
To sort the files in reverse order
$sort -r <file name>

To display only files  
$ll | grep "^-"
To display only directories
$ll | grep "^d"