> For the complete documentation index, see [llms.txt](https://alicenab.gitbook.io/linux/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alicenab.gitbook.io/linux/redhat/redhat-administration-1-rh124/chapter-5.md).

# Chapter 5

CREATING, VIEWING, AND EDITING TEXT FILES

## STDIN, STDOUT, STDERR

| NUMBER | CHANNEL NAME | DESCRIPTION     | DEFAULT CONNECTION | USAGE             |
| ------ | ------------ | --------------- | ------------------ | ----------------- |
| 0      | stdin        | Standard input  | Keyboard           | read only         |
| 1      | stdout       | Standard output | Terminal           | write only        |
| 2      | stderr       | Standard error  | Terminal           | write only        |
| 3+     | filename     | Other files     | none               | read and/or write |

<table><thead><tr><th width="266">redirection</th><th>redirects</th></tr></thead><tbody><tr><td>command > file</td><td>redirect and overwrite to file</td></tr><tr><td>command >> file</td><td>redirect and append to file</td></tr><tr><td>command 2> file</td><td>redirect stderr and overwrite file</td></tr><tr><td>command 2>/dev/null</td><td>redirect stderr to /dev/null</td></tr><tr><td>command > file 2>&#x26;1</td><td>1) redirect stdout and overwrite file, then<br>2) redirect stderr to stdout (same file)<br>file contains both stdout and stderr</td></tr><tr><td>command &#x26;> file</td><td>same with above example</td></tr><tr><td>command >> file 2>&#x26;1</td><td>1) redirect stdout and append file, then<br>2) redirect stderr to stdout (same file)<br>file contains both stdout and stderr</td></tr><tr><td>command &#x26;>> file</td><td>same with above example</td></tr><tr><td>command 2>&#x26;1 > file</td><td>1) redirect stderr to stdout (terminal), then<br>2) redirect stdout to file<br>stderr prints to terminal, file only contains stdout </td></tr></tbody></table>

Redirectionu pipe ilə işlətdiyimiz vaxt, pipe-dan sonrakı komandaya stdin daxil olmur.

Bu kimi hallarçün `tee` işlətmək lazımdır. tee özündən əvvəlki komandadan gələn stdout-u stdin kimi qəbul edir, və özündən sonrakı pipe-a stdout kimi ötürür.

<figure><img src="https://2273301741-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MaSvvJbAG6NSNXDy9Qs%2Fuploads%2F9bMx0xlMV1ZYNTW9WE82%2Fimage.png?alt=media&amp;token=a243edc6-9027-4aa7-b794-8b1565401a59" alt=""><figcaption></figcaption></figure>

```
ls > file | less         # empty output
ls -l | tee file | less  # writes to file, prints to output

# Merge commands should not be used with pipe commands:
find / -name passwd 2>&1 | less # normal
find -name / passwd &> | less.  # syntax error
-bash: syntax error near unexpected token `|'
```

```
# adding /home/user/bin directory to PATH variable:
export PATH=${PATH}:/home/user/sbin
```

```
# to see currently set variables:
set

# to see all environment variables:
env
```

To set persistent variables look for these files:

```
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
```

##
