1.4 KiB
1.4 KiB
Linux+ 1.5.2: Redirection and pipes
Output and errors in separate files, here documents with and without
expansion, tee, and file names with spaces through xargs.
Before you start
The lab clears away the files the tasks create, if they're there. Several
are in /tmp, which Ubuntu empties at boot, so do the tasks without a
reboot and run le-lab check before you clean up.
Tasks
- Make a directory
/tmp/redirand work in it. Runls /etc /nonexistentfour ways: output toout.txtand errors toerr.txt; both intoall.txt; and with2>&1 > only-out.txt. Watch where the error goes in the last one. - With here documents, write
user=$USERto/tmp/a.txtwith the variable expanded, and to/tmp/b.txtexactly as written. - Count the login shells in
/etc/passwd, most common first. Then savegetent passwdto/tmp/users.txtand count its lines in the same pipeline. - Make a directory
/tmp/xwith two files,a b.tmpandc d.tmp. Seefind ... | xargs rmfail on the spaces, then remove them safely withfindandxargs. Leave/tmp/xitself.
Hints
> out.txt 2> err.txt,> all.txt 2>&1; redirections apply left to right.<< EOFexpands variables;<< 'EOF'doesn't.cut -d: -f7 /etc/passwd | sort | uniq -c | sort -rn;getent passwd | tee /tmp/users.txt | wc -l.find /tmp/x -name '*.tmp' -print0 | xargs -0 rm.