

{"id":110055,"date":"2022-08-19T11:00:02","date_gmt":"2022-08-19T05:30:02","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=110055"},"modified":"2022-08-19T11:12:07","modified_gmt":"2022-08-19T05:42:07","slug":"pipes-and-filters-in-linux","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/","title":{"rendered":"Pipes and Filters in Linux"},"content":{"rendered":"<p>In this article, we will learn what pipes and filters are in Linux. We will learn in-depth of what pipes are and why they are used. We will also be looking into different filters that we use in Linux and go slightly deeper into some of the most commonly used filters.<\/p>\n<h3>What is a pipe in linux?<\/h3>\n<p>The pipe that we are referring to here has absolutely no similarity and has nothing to do with the pipes used to convey different substances. Instead, pipe here referred to a character on your keyboard: \u201c|\u201d. That\u2019s right, this vertical line is called a pipe.<\/p>\n<p>In the terminal, we use a pipe to connect 2 or more commands. Why do we connect? We connect them to provide a more specific or distinguished output.<\/p>\n<p>In simpler words, the pipe symbol takes sed the output of the first command as the input to the subsequent command. When we pipe the main command with any of the filters in Linux, we can get very specific answers.<\/p>\n<p>Since pipe helps you mash up many commands and run them at the same time, we can create really powerful and efficient commands that can handle really complex tasks in a flash.<\/p>\n<p>Instead of understanding pipes separately by taking individual examples, let us also understand what filters are then directory combine pipes and filters to get a better understanding and save time.<\/p>\n<h3>What are filters in linux?<\/h3>\n<p>In Linux, filters are a set of various commands that take in standard input (say from the main command) and then perform different options like sorting trimming, finding, lengthening, and so many more.<\/p>\n<p>By definition, filters take in standard input (stdin) and produce an output on standard output (stdout). Let us look at some of the filters in brief.<\/p>\n<h4>1. Linux cat command<\/h4>\n<p>The cat command on its own is a really powerful command which allows you to edit, create and manipulate files. But as a filter, it simply moves standard input to standard output.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/cat-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110131\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/cat-command.webp\" alt=\"cat command\" width=\"528\" height=\"805\" \/><\/a><\/p>\n<p>On piping the cat command with \u201ctac\u201d will print the data in your files in reverse order. If you are really interested in checking out the features of the cat command, feel free to check out my full-blown article on the command.<\/p>\n<p><strong>Syntax of Cat Command<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cat &lt;options&gt; &lt;filename&gt;<\/pre>\n<h4>2. Linux cut command<\/h4>\n<p>The cut command is a pretty simple command, as the name suggests, it cuts text from where you specify. After you chose to divide the text, you can even choose what to print.<\/p>\n<p><strong>Syntax of cut command:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cut &lt;options&gt; &lt;byte position&gt; &lt;filename&gt;<\/pre>\n<p>The cut command is a very versatile command as it lets you cut by various aspects like a hyphen (-), space, byte position, character or even a specific word or pattern<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/cut-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110132\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/cut-command.webp\" alt=\"cut command\" width=\"565\" height=\"435\" \/><\/a><\/p>\n<p>The above output is an example of cutting by the byte position. Let us take a look at some of the options that we can use with the cut command:<\/p>\n<h5>1. -c<\/h5>\n<p>This option lets you specify the character from where you want to cut.<\/p>\n<h5>2. -d<\/h5>\n<p>This option lets you select a specific section (like a hyphen or space) to cut.<\/p>\n<h5>3. -f<\/h5>\n<p>This option lets you specify the field you want to print after cutting.<\/p>\n<h5>4. -b<\/h5>\n<p>This option lets you specify the position of the byte you want to cut from.<\/p>\n<h5>5. &#8211;help<\/h5>\n<p>This option displays the help menu with all the options, uses and information regarding the command.<\/p>\n<h4>3. Linux grep command<\/h4>\n<p><strong>Syntax of grep command<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">grep &lt;options&gt; &lt;string pattern&gt; &lt;filename&gt;<\/pre>\n<p>The grep command is one of the most used commands when paired with filtering. The grep command is used to search a file(s) for a word(s), sentence(s), or any pattern of words or characters and displays all the lines that contain the same.<\/p>\n<p>We use the grep command both individually or by piping it:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/grep-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110133\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/grep-command.webp\" alt=\"grep command\" width=\"626\" height=\"295\" \/><\/a><\/p>\n<p>In the above output, grep was piped with the cat command, whereas in the below output, grep was run independently, yet produced the same output.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/example-of-grep-command-without-piping.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110134\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/example-of-grep-command-without-piping.webp\" alt=\"example of grep command without piping\" width=\"620\" height=\"329\" \/><\/a><\/p>\n<p>However, we cannot do this always. The grep command comes in really handy when we want to find something specific when searching in really long pieces of information, be it either text files or other pieces of data like environmental variables, network packets and so many more.<\/p>\n<p>Let us look at some options used with the grep command:<\/p>\n<h5>1. -i<\/h5>\n<p>This option makes the grep case insensitive.<\/p>\n<h5>2. -n<\/h5>\n<p>This option prints out the line numbers.<\/p>\n<h5>3. -c<\/h5>\n<p>This option gives the line number of the result you searched is in.<\/p>\n<h5>4. -v<\/h5>\n<p>This makes grep work like an inverted filter.<\/p>\n<h5>5.-w<\/h5>\n<p>This option matches the whole word you want to search.<\/p>\n<h5>6. -o<\/h5>\n<p>This option prints only the word you searched for and not the sentence.<\/p>\n<h5>7. -h<\/h5>\n<p>This option displays the help menu with all the different options.<\/p>\n<h5>8. -v<\/h5>\n<p>This option displays the information about the grip you are using.<\/p>\n<h4>4. Linux comm command<\/h4>\n<p>The comm command is simply used to compare 2 files. By default, the output of the comm command will have 3 columns, the first one contains the similarities between both the items and the remaining 2 columns carry the left out items of each of the files.<\/p>\n<p><strong>Syntax of Comm Command<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">comm &lt;options&gt; &lt;filname 1&gt; &lt;filename 2&gt;<\/pre>\n<p>Let us take an example to understand the comm command better.<\/p>\n<p>Let us take the below-given text files for example:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/comm-command-in-linux.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110136\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/comm-command-in-linux.webp\" alt=\"comm command in linux\" width=\"498\" height=\"232\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/linux-comm-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110137\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/linux-comm-command.webp\" alt=\"linux comm command\" width=\"510\" height=\"230\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Now if I compare both these text files using the comm command, The output will be as follows:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/comm-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110135\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/comm-command.webp\" alt=\"comm command\" width=\"628\" height=\"367\" \/><\/a><\/p>\n<p>We can also pipe the comm command to different pieces of information.<\/p>\n<h4>5. Linux sed command<\/h4>\n<p>The sed command is another file editing and a manipulating tool similar to cat. Sed stands for stream editor, or basically file editor. The main difference between sed with other file editing commands is that this editing is not permanent, the edits you make remain only on the display and the actual file contents remain the same.<\/p>\n<p><strong>Syntax of linux sed command<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sed &lt;options&gt; &lt;script&gt; &lt;filename&gt;<\/pre>\n<p>Let us understand the sed command by taking a small example. Say I have the below-given text file:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/sample-text-file-to-apply-sed-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110380\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/sample-text-file-to-apply-sed-command.webp\" alt=\"sample text file to apply sed command\" width=\"797\" height=\"208\" \/><\/a><\/p>\n<p>If I pipe the sed command to the cat command, I get the following output:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/piping-sed-command-with-cat-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110382\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/piping-sed-command-with-cat-command.webp\" alt=\"piping sed command with cat command\" width=\"796\" height=\"232\" \/><\/a><\/p>\n<p>The following command I ran, replaced the word \u201cLambo\u201d with \u201cferrari\u201d. As mentioned earlier, the changes only apply on the screen, which means If I go to the file again, the content will be unchanged. Let us look at some of the options used long with the sed command:<\/p>\n<h5>1. -n<\/h5>\n<p>This option activates quiet mode.<\/p>\n<h5>2. -e<\/h5>\n<p>This option adds the script to the commands that are to be executed.<\/p>\n<h5>3. -f<\/h5>\n<p>This option adds the contents of the script file to the commands.<\/p>\n<h5>4. &#8211;sandbox<\/h5>\n<p>This option operates in sandbox mode.<\/p>\n<h5>5. -z<\/h5>\n<p>This option displays the help manual<\/p>\n<h5>6. -v<\/h5>\n<p>This option prints information about the version of the sed command<\/p>\n<h4>6. Linux tee command<\/h4>\n<p>The tees command just like sed, is very similar to the cat command, except 1 notch better. The tee command takes the standard input on standard output and also puts them in a file. We can use the tee command by piping it with other commands to make better use of it.<\/p>\n<p><strong>Syntax of tee command:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">tee &lt;options&gt; &lt;filename&gt;\r\n<\/pre>\n<p>Let us understand the tees command better by taking an example. Let us consider the below-given text file:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/sample-text-file-to-test-the-tee-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110383\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/sample-text-file-to-test-the-tee-command.webp\" alt=\"sample text file to test the tee command\" width=\"714\" height=\"205\" \/><\/a><\/p>\n<p>If I pipe this command with a tee command:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/using-tee-command-to-copy-contents-of-one-file-to-another.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110384\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/using-tee-command-to-copy-contents-of-one-file-to-another.webp\" alt=\"using tee command to copy contents of one file to another\" width=\"714\" height=\"434\" \/><\/a><\/p>\n<p>The above command copied the contents of the file into another file. I can do the same thing using the cp command also.<\/p>\n<p>I can also add new content to a file by using the option \u201c-a\u201d<\/p>\n<p>Since we are on the topic of options, let us look at some used with the tee command.<\/p>\n<h5>1. -a<\/h5>\n<p>This option appends the data to a given file.<\/p>\n<h5>2. -i<\/h5>\n<p>This option ignores the interrupt signals<\/p>\n<h5>3. -p<\/h5>\n<p>This option diagnoses errors while writing to non-pipes<\/p>\n<h5>4. &#8211;output-error=&lt;mode&gt;<\/h5>\n<p>This option sets the behavior in write error mode.<\/p>\n<h5>5. -v<\/h5>\n<p>This option displays the version information about the tee command<\/p>\n<h4>7. Linux tr command<\/h4>\n<p>The tr command is used to change the text from lower case to uppercase and vice versa. It cannot get any simpler or straightforward than that. Tr stands for translate. To use the tr command we follow the syntax:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">tr\u00a0&lt;options&gt;\u00a0&lt;old\u00a0text&gt;\u00a0&lt;new\u00a0text&gt;\u00a0&lt;filename&gt;<\/pre>\n<p>Let us take an example to understand better:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/tr-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110139\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/tr-command.webp\" alt=\"tr command\" width=\"716\" height=\"481\" \/><\/a><\/p>\n<p>In the above example, I uppercased the previously lowercase l, f, p, and b.<\/p>\n<p>Apart from just changing lower case letters to uppercase and vice versa, it can also do things like squeezing content into one single line, making it case sensitive and so many more with the help of the options available.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/squeezing-the-content-of-the-text-file-into-a-single-line.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110140\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/squeezing-the-content-of-the-text-file-into-a-single-line.webp\" alt=\"squeezing the content of the text file into a single line\" width=\"1434\" height=\"47\" \/><\/a><\/p>\n<p>In the above output, I squeezed the content of the text file into a single line by using the command <strong>cat &lt;filename&gt; | tr \u2018\\n\u2019 \u2018 \u2019<\/strong><\/p>\n<p>Since we are on the topic of options, let us look at some used with the tr command.<\/p>\n<h5>1. -s<\/h5>\n<p>This option squeezes the occurrence of multiple characters into one.<\/p>\n<h5>2. rot13<\/h5>\n<p>This option encrypts the text. It is case-sensitive.<\/p>\n<h5>3. -d<\/h5>\n<p>this option is used to delete characters<\/p>\n<h4>8. Linux uniq command<\/h4>\n<p>The uniq command is short for unique, and as the name suggests, it keeps only the unique contents of the file and removes the repeated lines.<\/p>\n<p><strong>Syntax of linux uniq command<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">uniq &lt;options&gt; &lt;filename&gt;<\/pre>\n<p>Let us understand this command better by taking an example. Let us consider the below-given text file:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/sample-text-file-to-test-the-uniq-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110385\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/sample-text-file-to-test-the-uniq-command.webp\" alt=\"sample text file to test the uniq command\" width=\"622\" height=\"204\" \/><\/a><\/p>\n<p>Now If I want to remove the repeated entries, I need to pipe the uniq command with the sort command as follows:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/using-uniq-command-to-print-out-the-unique-elements-of-the-file.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110386\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/using-uniq-command-to-print-out-the-unique-elements-of-the-file.webp\" alt=\"using uniq command to print out the unique elements of the file\" width=\"621\" height=\"370\" \/><\/a><\/p>\n<p>Apart from suppressing duplicate entries in the file, the uniq command can also do different things like counting the occurrence of the word:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/counting-the-occurences-of-a-word-using-the-uniq-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110387\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/counting-the-occurences-of-a-word-using-the-uniq-command.webp\" alt=\"counting the occurences of a word using the uniq command\" width=\"665\" height=\"171\" \/><\/a><\/p>\n<p>Or displaying the repeated lines in a file as shown below and so many more.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/printing-the-repeated-lines-using-the-uniq-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110388\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/printing-the-repeated-lines-using-the-uniq-command.webp\" alt=\"printing the repeated lines using the uniq command\" width=\"678\" height=\"125\" \/><\/a><\/p>\n<p>We can do many tasks using different available options like:<\/p>\n<h5>1. -c<\/h5>\n<p>This option counts the occurrence of a word.<\/p>\n<h5>2. -d<\/h5>\n<p>This option displays the repeated lines.<\/p>\n<h5>3. -u<\/h5>\n<p>This option displays the unique lines.<\/p>\n<h5>4. -s<\/h5>\n<p>This option ignores the characters in comparison.<\/p>\n<h5>5. -f<\/h5>\n<p>This option ignores fields in comparison.<\/p>\n<h4>9. Linux wc command<\/h4>\n<p>The wc command is a very handy and powerful tool that helps in the process of counting the lines, words and characters in a file. The wc command is usually used by piping it to some main command.<\/p>\n<p><strong>Syntax of wc command<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">wc &lt;options&gt; &lt;filename&gt;<\/pre>\n<p>By default, the wc command prints the number of lines, number of characters, and the number of words one after the other separated by a space<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/wc-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110389\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/wc-command.webp\" alt=\"wc command\" width=\"534\" height=\"280\" \/><\/a><\/p>\n<p>In the above output, there are 8 words, 8 lines and 62 characters.<\/p>\n<p>Remember when I told that the wc command was powerful? Well it can even tell you the count of lines, words and characters in multiple files.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/printing-count-information-of-multiple-files-using-the-wc-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110390\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/printing-count-information-of-multiple-files-using-the-wc-command.webp\" alt=\"printing count information of multiple files using the wc command\" width=\"738\" height=\"145\" \/><\/a><\/p>\n<p>You can also use the wc command by piping it, here\u2019s an example:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/piping-the-wc-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110391\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/07\/piping-the-wc-command.webp\" alt=\"piping the wc command\" width=\"602\" height=\"125\" \/><\/a><\/p>\n<p>Let us look at some of the options that are used with the wc command:<\/p>\n<h5>1. -c<\/h5>\n<p>This option prints the count of the bytes.<\/p>\n<h5>2. -m<\/h5>\n<p>This option prints the count so the characters.<\/p>\n<h5>3. -l<\/h5>\n<p>This option prints the count of the lines.<\/p>\n<h5>4. -w<\/h5>\n<p>This option prints the count of the words.<\/p>\n<h5>5. -L<\/h5>\n<p>This option prints the maximum display width.<\/p>\n<h4>10. Linux od command<\/h4>\n<p><strong>Syntax of od command<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">od &lt;-b&gt;\/&lt;-t x1&gt;\/&lt;-c&gt;&lt;filename&gt;<\/pre>\n<p>The od command is short for Octal Dump. This command displays the contents of files in different forms like hexadecimal, octal, or ASCII characters. Let us see the different syntaxes we use for the different formats along with an example for each:<\/p>\n<h5>1. od -b &lt;filename&gt;<\/h5>\n<p>This syntax displays the contents of a file in octal format.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/displaying-the-contents-of-a-file-in-octal-format-using-the-od-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110142\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/displaying-the-contents-of-a-file-in-octal-format-using-the-od-command.webp\" alt=\"displaying the contents of a file in octal format using the od command\" width=\"735\" height=\"147\" \/><\/a><\/p>\n<h5>2. od -t x1 &lt;filename&gt;<\/h5>\n<p>This syntax displays the contents of a file in hexadecimal bytes format.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/displaying-the-contents-of-a-file-in-hexa-decimal-byte-format-using-the-od-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110143\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/displaying-the-contents-of-a-file-in-hexa-decimal-byte-format-using-the-od-command.webp\" alt=\"displaying the contents of a file in hexa decimal byte format using the od command\" width=\"646\" height=\"168\" \/><\/a><\/p>\n<h5>3. od -c &lt;filename&gt;<\/h5>\n<p>This syntax displays the contents of a file in ASCII format.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/displaying-the-contents-of-a-file-in-ASCII-format-using-the-od-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110144\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/displaying-the-contents-of-a-file-in-ASCII-format-using-the-od-command.webp\" alt=\"displaying the contents of a file in ASCII format using the od command\" width=\"710\" height=\"143\" \/><\/a><\/p>\n<h4>11. Linux sort command<\/h4>\n<p><strong>Syntax of sort command<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sort &lt;options&gt; &lt;filename&gt;<\/pre>\n<p>The name says it all, the sort command helps in sorting the contents of a file in different ways and methods. Let us take a look at some examples:<\/p>\n<p>Normal sorting: This will sort the contents of a file alphabetically.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/sort-command.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110145\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/sort-command.webp\" alt=\"sort command\" width=\"520\" height=\"623\" \/><\/a><\/p>\n<p>Sorting a column: this command will sort a specified column of the file.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/sorting-a-column.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110146\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/sorting-a-column.webp\" alt=\"sorting a column\" width=\"520\" height=\"574\" \/><\/a><\/p>\n<p>Numeric sorting: you can sort content in a file numerically by using the option \u201c-n\u201d. You may also have to specify the column number.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/numeric-sorting-a-column.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110147\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/numeric-sorting-a-column.webp\" alt=\"numeric sorting a column\" width=\"632\" height=\"346\" \/><\/a><\/p>\n<h4>12. Linux gzip\/gunzip commands<\/h4>\n<p>The gunzip and gzip commands are very similar to unzipping and zipping files. We follow the following commands to gzip and gunzip:<\/p>\n<p>gzip &lt;filename&gt;<br \/>\ngunzip &lt;filename&gt;<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/gunzip-and-gip-commands.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110148\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/gunzip-and-gip-commands.webp\" alt=\"gunzip and gip commands\" width=\"676\" height=\"159\" \/><\/a><\/p>\n<p>Let us look at some of the commonly used options used with the command:<\/p>\n<h5>1. -a<\/h5>\n<p>This option converts end-of-lines using local conventions. This command can also be written as \u2018&#8211;ascii\u2019. Please note that this option is supported only on some non-Unix systems.<\/p>\n<h5>2. -c<\/h5>\n<p>This option writes output on standard output. It keeps original files unchanged.<\/p>\n<h5>3. -d<\/h5>\n<p>This command decompressed the files. It can also be written as \u2018&#8211;decompress\u2019 or \u2018&#8211;uncompress\u2019<\/p>\n<h5>4. -L<\/h5>\n<p>This option displays the information about the gunzip license.<\/p>\n<h5>5. -n<\/h5>\n<p>This option does not save the original file name and timestamp when decompressing it.<\/p>\n<h5>6. -N<\/h5>\n<p>This option is the exact opposite of the option \u2018-n\u2019, it saves the original file name and timestamp when decompressing it.<\/p>\n<h5>7. -q<\/h5>\n<p>This option suppresses all the warnings.<\/p>\n<h5>8. -S<\/h5>\n<p>This option uses the suffix \u2018.suf\u2019, instead of \u2018.gz\u2019 when decompressing.<\/p>\n<h5>9. -t<\/h5>\n<p>This option performs a test by checking the integrity of the decompressed file.<\/p>\n<h5>10. -v<\/h5>\n<p>This option provides a verbose to give a better understanding of what is happening.<\/p>\n<h5>12. -V<\/h5>\n<p>This option displays the information about the version of gunzip you are using.<\/p>\n<h5>13. -H<\/h5>\n<p>This option displays the help menu.<\/p>\n<h4>13. Linux less command<\/h4>\n<p>As the name suggests, this command shows less information for more lengthy pieces of information. It cut shorts the data and displays only the important data.<\/p>\n<p>We can also improve the functionalities of the commands by using many other commands. For example, the option \u201c-s\u201d suppresses the blank lines, and the option \u201c-&lt;n&gt;\u201d displays only the number of lines you specified.<\/p>\n<p><strong>Syntax of less command<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">less &lt;options&gt; &lt;filename&gt;\r\n<\/pre>\n<h4>14. Linux more command<\/h4>\n<p>The more command is exactly the same as the less command, with only one difference. The more command displays a part of the information, and if you wish to see more of it, just press the enter button on your keyboard.<\/p>\n<p><strong>Syntax of more command<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">more &lt;options&gt; &lt;filename&gt;<\/pre>\n<h3>Creating your own filters in Linux<\/h3>\n<p>We have seen 15 beautiful examples of filters, but did you also know that we can create our own? Well, it is partially true, we cannot create our own commands (like grep, sed, sort, etc), but we can create shell programs that when run, act as filters.<\/p>\n<p>For example, we can create a filter that catches files greater than a specific size and then perform some actions using the following syntax:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if [ $SIZE -gt &lt;size&gt; ]\r\nthen\r\n&lt;set of actions&gt;\r\nfi<\/pre>\n<p>Let us create a simple program that prints the name, size, date, and time of files greater than 10000:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/shell-program-of-the-filter-we-are-creating.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110149\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/shell-program-of-the-filter-we-are-creating.webp\" alt=\"shell program of the filter we are creating\" width=\"502\" height=\"188\" \/><\/a><\/p>\n<p>Instead of writing such big programs, you can use the \u201cawk\u201d command to write simple yet effective 1 line programs that work very similar to filters. You can write the above shell program using the \u201cawk\u201d command as shown below:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/awk-command-serving-same-purpose-of-a-filter.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-110150\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/awk-command-serving-same-purpose-of-a-filter.webp\" alt=\"awk command serving same purpose of a filter\" width=\"692\" height=\"35\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>In this article, you have learned what filters and pipes are in Linux. We have also seen a lot of filters along with practical examples like cat, cut, grep, comm, sed, tee, tr, uniq, wc, od, sort, gzip, Less, and More.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will learn what pipes and filters are in Linux. We will learn in-depth of what pipes are and why they are used. We will also be looking into different filters&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":110093,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[27016,27014,27015],"class_list":["post-110055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-filter-in-linux","tag-pipes-and-filters-in-linux","tag-pipes-in-linux"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Pipes and Filters in Linux - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about pipes and filters in linux. See what is pipe in linux and filter in linux. See some of the linux filters with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pipes and Filters in Linux - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about pipes and filters in linux. See what is pipe in linux and filter in linux. See some of the linux filters with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-19T05:30:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-19T05:42:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/pipes-and-filters-in-linux.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pipes and Filters in Linux - DataFlair","description":"Learn about pipes and filters in linux. See what is pipe in linux and filter in linux. See some of the linux filters with examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/","og_locale":"en_US","og_type":"article","og_title":"Pipes and Filters in Linux - DataFlair","og_description":"Learn about pipes and filters in linux. See what is pipe in linux and filter in linux. See some of the linux filters with examples.","og_url":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2022-08-19T05:30:02+00:00","article_modified_time":"2022-08-19T05:42:07+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/pipes-and-filters-in-linux.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Pipes and Filters in Linux","datePublished":"2022-08-19T05:30:02+00:00","dateModified":"2022-08-19T05:42:07+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/"},"wordCount":2503,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/pipes-and-filters-in-linux.webp","keywords":["filter in linux","Pipes and Filters in Linux","pipes in linux"],"articleSection":["Linux Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/","url":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/","name":"Pipes and Filters in Linux - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/pipes-and-filters-in-linux.webp","datePublished":"2022-08-19T05:30:02+00:00","dateModified":"2022-08-19T05:42:07+00:00","description":"Learn about pipes and filters in linux. See what is pipe in linux and filter in linux. See some of the linux filters with examples.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/pipes-and-filters-in-linux.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/05\/pipes-and-filters-in-linux.webp","width":1200,"height":628,"caption":"pipes and filters in linux"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/pipes-and-filters-in-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Linux Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/linux\/"},{"@type":"ListItem","position":3,"name":"Pipes and Filters in Linux"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/110055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=110055"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/110055\/revisions"}],"predecessor-version":[{"id":110392,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/110055\/revisions\/110392"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/110093"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=110055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=110055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=110055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}