Redirection of standard error

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search
← here stringsHomeRedirection of standard output →

To redirect standard error into file called error.log, enter:

command-name 2>error.log

Find all .profile files in /home directory and log errors to /tmp/error file, enter:

find /home -name .profile 2>/tmp/error

Sample output:

/home/t2/.profile
/home/vivek/ttt/skel/.profile

To view errors, enter:

more /tmp/error

Sample outputs:

find: `/home/vivek/.cpan/build/Acme-POE-Tree-1.01-qqmq77': Permission denied
find: `/home/vivek/.cpan/build/Lchown-1.00-uOM4tb': Permission denied
find: `/home/vivek/.cpan/build/IO-Tty-1.07-F9rDy3': Permission denied
find: `/home/vivek/.cpan/build/POE-Test-Loops-1.002-9AjIro': Permission denied
find: `/home/vivek/.cpan/build/POE-1.003-KwXVB1': Permission denied
find: `/home/vivek/.cpan/build/Curses-1.27-ZLo169': Permission denied

Redirect Script Errors

You can redirect script error to a log file called scripts.err:

./script.sh 2>scripts.err
/path/to/example.pl 2>scripts.err

Append To Error Log

You can append standard error to end of error.log file using >> operator:

command-name 2>>error.log
./script.sh 2>>error.log
/path/to/example.pl 2>>error.log

External links

← here stringsHomeRedirection of standard output →