Skip to content
This repository was archived by the owner on Jun 5, 2024. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion tail_less_cat_head.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# <a name="cat-less-tail-and-head"></a>Cat, Less, Tail and Head
# <a name="cat--tail-and-head"></a>Cat, Less, Tail, Head and Tee

**Table of Contents**

Expand Down Expand Up @@ -27,6 +27,14 @@
* [combining head and tail](#combining-head-and-tail)
* [Further Reading for head](#further-reading-for-head)
* [Text Editors](#text-editors)
* [Tee](#Tee)
* [Write output to stdout, and also to a file](#output-to-stdout)
* [Write the output to two commands](#output-to-two-commands)
* [Misc Tee Command Operations](#Misc)





<br>

Expand Down Expand Up @@ -680,3 +688,39 @@ Powerful text editors
* [sublime](https://www.sublimetext.com/)

Check out [this analysis](https://github.com/jhallen/joes-sandbox/tree/master/editor-perf) for some performance/feature comparisons of various text editors


## <a name="Tee"></a>Tee

### <a name="output-to-stdout"></a>Write output to stdout, and also to a file
```
The following command displays output only on the screen (stdout).
$ ls

The following command writes the output only to the file and not to the screen.
$ ls > file

The following command (with the help of tee command) writes the output both to the screen (stdout) and to the file.
$ ls | tee file
```

### <a name="output-to-two-commands"></a>Write the output to two commands
```
You can also use tee command to store the output of a command to a file and redirect the same output as an input to another command.

The following command will take a backup of the crontab entries, and pass the crontab entries as an input to sed command which will do the substituion. After the substitution, it will be added as a new cron job.

$ crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab –
```

### <a name="Misc"></a>Misc Tee Command Operations
```
By default tee command overwrites the file. You can instruct tee command to append to the file using the option –a as shown below.

$ ls | tee –a file

You can also write the output to multiple files as shown below.

$ ls | tee file1 file2 file3

```