···6060feed the `cut` command's standard input using the `<` operator:
61616262```console
6363-$ cut -d' ' -f2 < uname.txt
6363+$ cut -d ' ' -f 2 < uname.txt
6464shachi
6565chrysalis
6666kos-mos
···100100write it like this:
101101102102```sh
103103-cat uname.txt | cut -d' ' -f2
103103+cat uname.txt | cut -d ' ' -f 2
104104```
105105106106[The mnemonic we use for remembering the `cut` command is that fields are
···110110This will get you the exact same output:
111111112112```console
113113-$ cat uname.txt | cut -d' ' -f2
113113+$ cat uname.txt | cut -d ' ' -f 2
114114shachi
115115chrysalis
116116kos-mos
···123123example, if you wanted to sort them you could pipe the result to `sort`:
124124125125```console
126126-$ cat uname.txt | cut -d' ' -f2 | sort
126126+$ cat uname.txt | cut -d ' ' -f 2 | sort
127127chrysalis
128128kos-mos
129129ontos
···224224go to the same file. You can do this with a command like this:
225225226226```
227227+$ rustc foo.rs > foo.log 2>&1
228228+```
229229+230230+This tells the shell to point standard out to `foo.log`, and then standard
231231+error to standard out (which is now `foo.log`). There's a footgun here though;
232232+the order of the redirects matters. Consider the following:
233233+234234+```
227235$ rustc foo.rs 2>&1 > foo.log
236236+error: expected one of `!` or `::`, found `main`
237237+ --> foo.rs:1:5
238238+ |
239239+1 | fun main() {}
240240+ | ^^^^ expected one of `!` or `::`
241241+242242+error: aborting due to previous error
243243+$ cat foo.log
244244+$ # foo.log is empty, why???
228245```
229246230230-This tells the shell to point standard error to standard out and then the
231231-combined output to `foo.log`. There's a short form of this too:
247247+We wanted to redirect stderr to `foo.log`, but that didn't happen. Why? Well,
248248+the shell considers our redirects one at a time from left to right. When the
249249+shell sees `2>&1`, it hasn't considered `> foo.log` yet, so standard out (`1`)
250250+is still our terminal. It dutifully redirects stderr to the terminal, which is
251251+where it was already going anyway. Then it sees `1 > foo.log`, so it redirects
252252+standard out to `foo.log`. That's the end of it though. It doesn't
253253+retroactively redirect standard error to match the new standard out, so our
254254+errors get dumped to our terminal instead of the file.
255255+256256+Confusing right? Lucky for us, there's a short form that redirects both at the
257257+same time, making this mistake impossible:
232258233259```
234260$ rustc foo.rs &> foo.log
235261```
236262237237-[Where can I expect to use that?](conversation://Mara/hmm)
263263+This will put standard out and standard error to `foo.log` the same way that
264264+`> foo.log 2>&1` will.
238265239239-[It's a bourne shell extension, but I've tested it in `zsh` and `fish`. You can
240240-also do `&|` to pipe both standard out and standard error at the same time in
241241-the same way you'd do `2>&1 | whatever`.](conversation://Cadey/enby)
266266+[Will that work in every shell?](conversation://Mara/hmm)
242267243243-That will put standard out and standard error to `foo.log` the same way that
244244-`2>&1 > foo.log` will. You can also use this with `>>`:
268268+[It's a bourne shell (`bash`) extension, but I've tested it in `zsh` and `fish`.
269269+You can also do `&|` to pipe both standard out and standard error at the same
270270+time in the same way you'd do `2>&1 | whatever`.](conversation://Cadey/enby)
271271+272272+You can also use this with `>>`:
245273246274```
247275$ rustc foo.rs &>> foo.log
···265293266294[How do I redirect standard in to a file?](conversation://Mara/hmm)
267295268268-The answer there is not directly! There is a workaround in the form of a tool
269269-called `tee` which outputs its standard in to both standard out and a file. For
270270-example:
296296+Well, you don't. Standard in is an input, so you can change where it comes
297297+_from_, not where it goes.
298298+299299+But, maybe you want to make a copy of a program's input and send it somewhere
300300+else. There is a way to do _that_ using a command called `tee`. `tee` copies
301301+its standard input to standard output, but it also writes a second copy to a
302302+file. For example:
271303272304```console
273305$ dmesg | tee dmesg.txt | grep 'msedge'
···345377346378---
347379348348-Thanks to violet spark for looking over this post and fact-checking as well as
349349-helping mend some of the brain dump and awkward wording into more polished
350350-sentences.
380380+Thanks to violet spark, cadence, and AstroSnail for looking over this post and
381381+fact-checking as well as helping mend some of the brain dump and awkward
382382+wording into more polished sentences.