# Piping and Redirection

## 1.<mark style="color:red;">Redirect</mark>

<table><thead><tr><th>Stream Name</th><th width="255">Description</th><th></th></tr></thead><tbody><tr><td>Standard Input (STDIN)</td><td>Data fed into the program</td><td></td></tr><tr><td>Standard Output (STDOUT)</td><td>Output from the program</td><td></td></tr><tr><td>Standard Error (STDERR)</td><td>Error messages (defaults to)</td><td></td></tr></tbody></table>

#### Type Standard

1. Standard Input   <mark style="color:blue;">0 ( STDIN )</mark>
2. Standard Output    <mark style="color:green;">1  ( STDOUT )</mark>
3. Standard Error        <mark style="color:red;">2 ( STDERR )</mark>

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FGFCvuxIUNTTnzes6uzYx%2F1.png?alt=media&#x26;token=4d534714-3621-4be0-9117-fb4a97f8579d" alt=""><figcaption></figcaption></figure>

* Redirecting to an Existing File

> In Case Redirect Output , U Can Using <mark style="color:red;">`>`</mark> Operator To Store Or Redirect Output In File

```bash
kali@kali:~$ echo "that is maintained and funded by Offensive Security" >>
redirection_test.txt
kali@kali:~$ cat redirection_test.txt
Kali Linux is an open source project
that is maintained and funded by Offensive Security
```

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FVNlgzgWTUxVsJfqKg5iV%2F2.png?alt=media&#x26;token=0309f1d3-828e-4798-a5cb-2cd24f2160ac" alt=""><figcaption></figcaption></figure>

* **Redirecting from a File**

```sh
root@root:~$ wc -m < php.php
89
```

* Redirecting to a New File

```markdown
kali@kali:~$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
kali@kali:~$ echo "test"
test
kali@kali:~$ echo "test" > redirection_test.txt
kali@kali:~$ ls
Desktop Documents Downloads Music Pictures Public redirection_test.txt Template
kali@kali:~$ cat redirection_test.txt
test
kali@kali:~$ echo "Kali Linux is an open source project" > redirection_test.txt
kali@kali:~$ cat redirection_test.txt
Kali Linux is an open source project
```

> In Case Insert In File Not Use Override In Case Using Just <mark style="color:red;">`>`</mark> U Can Use <mark style="color:red;">`>>`</mark> To Insert In File , And Save The Old Value

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2Fyo1jTmQV1Hsc9FtyibxJ%2F3.png?alt=media&#x26;token=888c9519-b6ff-49ae-b3bd-87e7378b62e6" alt=""><figcaption></figcaption></figure>

* Redirecting <mark style="color:red;">STDERR</mark>

```sh
kali@kali:~$ ls .
Desktop Documents Downloads Music Pictures Public redirection_test.txt Template
kali@kali:~$ ls ./test
ls: cannot access '/test': No such file or directory
kali@kali:~$ ls ./test 2>error.txt
```

> in Case Passing <mark style="color:green;">STRDINT</mark> Standard Input Using <mark style="color:red;">`<`</mark>

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FMzWSaYsgRbKJ86Onf9z5%2F4.png?alt=media&#x26;token=842054b7-8076-4048-8b72-4914ad9c9dc0" alt=""><figcaption></figcaption></figure>

## &#x20;2.<mark style="color:green;">Piping</mark>

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FV6XAo9TlJKmdbY5vFaHb%2F5.png?alt=media&#x26;token=2f00d801-b73e-482f-bd39-65953ec121cb" alt=""><figcaption></figcaption></figure>

> Return Result From **1st Function** Or Output ***And Passing As A Value To 2nd Tool Or Function***

> <mark style="color:red;">`tee`</mark> Command Using To Show Result And Store In File , U Can Append In File Because IF U Use Normal Use Delete Old Data, U Can Use Switch <mark style="color:red;">`-a`</mark> To Append  <mark style="color:red;">`ls | tee -a`</mark>

> And U Can Using Other <mark style="color:red;">`xargs`</mark> To Control Result And Execute Same Actions

<figure><img src="https://4250388013-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcgRjLSWS0JF8FXrQAeJd%2Fuploads%2FgbcUevRqCXfZ4v1xGKZH%2F6.png?alt=media&#x26;token=194d8434-85be-4e34-9e27-e041a2cc4f5e" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
In Case Show Errors In Kali U Can Show Result And Comments In The Kali website Bugs And Search From Your Errors [https://bugs.kali.org](https://bugs.kali.org/)

\
Kali Linux adheres to the [filesystem hierarchy standard (FHS)](https://wiki.linuxfoundation.org/lsb/fhs) Which provides a familiar and universal layout for all Linux users
{% endhint %}
