Redirection
> writes, >> appends, < reads, 2> redirects errors, &> sends both and 2>&1 merges errors into output. /dev/null discards output.
Example
d=$(mktemp -d); cd "$d"
echo one > f; echo two >> f
cat f
ls /nonexistent 2> err.txt; wc -l < err.txt
ls /nonexistent > both.txt 2>&1; wc -l < both.txt
echo hidden > /dev/null
cd /; rm -r "$d"Result
one two 1 1
Exercise
Redirect errors.
cmd err.log
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.