DEV Community

Chirag Kumar
Chirag Kumar

Posted on

Filter & IO redirection command.

Grep

grep command is used to find texts from any text input. Passwd file: stores information about all the users in the system.
Image description

➔ Finding line which contains word as “root” from /etc/passwd file.

Image description

➔ Linux is case sensitive, Root is different that root. Ignoring case in grep with -i option.

Image description

➔ To display things except the given word use -v option

Filter Commands

• less: Displays file content page wise or line wise. Ex: less /etc/passwd

Image description

• more

Image description

• head

Image description

• tail

Image description

• cut

Image description

• sed

Image description

I/O redirection

I/O redirection is accomplished using a redirection operator which allows the user to specify the input or output data be redirected to (or from) a file. Note that redirection always results in the data stream going to or coming from a file (the terminal is also considered a file).

➔ Create a file named DevOps tools with below content.

Image description

➔ Search for text “tech” replace it with “tools” and redirect output to a new file.

Image description

Image description

➔ Appending another output in same file with “>>” .

Image description

➔ Redirecting only error to a file “2>>”.

Image description

➔ Redirecting all the output to a file “&>>”.

Image description

Piping

So far we've dealt with sending data to and from files. Now we'll look at a mechanism for sending data from one program to another. It's called piping and the operator we use is ( | ). What this operator does is feed the output from the program on the left as input to the program on the right.

Image description

Find

The 'find' command is your go-to tool for locating files and directories in a Linux system. It's versatile, allowing you to search based on name, size, type, and other criteria. Let's dive into the basic usage of the 'find' command.

Image description

Image description

Top comments (0)