3. Use Input / Output Redirection / Compare Text Files / Compare Binary Files

So we have done with the manipulation of text files now its time to play with files. Now in this section, I am gonna introduce you to a variety of commands used to manipulate files for easy file and text handling in the terminal.

1. Introduction to pipes “|” in Command Line

pipe is a form of redirection that is used in Linux and other Unix-like operating systems to send the output of one program to another program for further processing. A pipe is designated in commands by the vertical bar character. The general syntax for pipes is:

command_1 | command_2 [| command_3 . . . ]

Pipes are mostly used in Linux and other Unix-like OS for better results and it increases the efficiency of the commands.

As you can see here I have used two different commands simultaneously “cat” for printing all content onto the terminal and “sort” to sort the file contents alphabetically.

2. “du”  command

du is used to display the space allocated by the files in the current directory.


du [OPTION]... --files0-from=F

Here I’ve used “du” for showing the size of each directory in “var” with the help of some options “-sch” (“s” for displaying subdirectories size separately, “c” for displaying grand total, “h” for human-readable size of the directories)  also used piping with “sort” command for sorting it according to size of directories.

3. Redirection using “>”

You can cat the contents of one file to another file using simple redirection in between the files.

4. Appending using “>>”

We can also use “cat” command to append all content of one text file to another text file.

Here you can clearly see that, using “>>”  I am able to append to all the content of a file to another file.

5. Format Text using “fmt”

You can format a file that contains unusual spaces and tabs extra new lines. Basically using different options you can format your text file as you wish. Use “man fmt” command to see more commands.

Important: I encourage you to go through the man page of a command line tool that you wanted to use. Because that gives a big picture of a tool and you got some good information about the tool.




Written by Anandesh

I am a #Linux lover and very much excited about technology and new thing. Love to #read_books. Curiosity is my best teacher. I am still☺️ understanding myself.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2. Create and Edit Text Files Part II – (LFCSA)

How to install VLC on Kali Linux