OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

5.2.2. Examples‌


5.2.2.1. Analyzing errors


If your process generates a lot of errors, this is a way to thoroughly examine them:


command 2>&1 | less


This is often used when creating new software using the make command, such as in:


andy:~/newsoft> make all 2>&1 | less

--output ommitted--

andy:~/newsoft> make all 2>&1 | less

--output ommitted--


image


5.2.2.2. Separating standard output from standard error


Constructs like these are often used by programmers, so that output is displayed in one terminal window, and errors in another. Find out which pseudo terminal you are using issuing the tty command first:


andy:~/newsoft> make all 2> /dev/pts/7


image


5.2.2.3. Writing to output and files simultaneously


You can use the tee command to copy input to standard output and one or more output files in one move. Using the -a option to tee results in appending input to the file(s). This command is useful if you want to both see and save output. The > and >> operators do not allow to perform both actions simultaneously.


This tool is usually called on through a pipe (|), as demonstrated in the example below:


mireille ~/test> date | tee file1 file2

Thu Jun 10 11:10:34 CEST 2004


mireille ~/test> cat file1

Thu Jun 10 11:10:34 CEST 2004


mireille ~/test> cat file2

Thu Jun 10 11:10:34 CEST 2004


mireille ~/test> uptime | tee -a file2

11:10:51 up 21 days, 21:21, 57 users, load average: 0.04, 0.16, 0.26


mireille ~/test> cat file2

Thu Jun 10 11:10:34 CEST 2004

11:10:51 up 21 days, 21:21, 57 users, load average: 0.04, 0.16, 0.26

mireille ~/test> date | tee file1 file2

Thu Jun 10 11:10:34 CEST 2004


mireille ~/test> cat file1

Thu Jun 10 11:10:34 CEST 2004


mireille ~/test> cat file2

Thu Jun 10 11:10:34 CEST 2004


mireille ~/test> uptime | tee -a file2

11:10:51 up 21 days, 21:21, 57 users, load average: 0.04, 0.16, 0.26


Top OS Cloud Computing at OnWorks: