random unix notes (part II)
Sat 26 December 2015
More about file descriptor can be found in this stackoverflow answer and this tiny tutorial. In short, file descriptors are located under /dev/fd/ (e.g. stdin is /dev/fd/0) and an unnamed pipe can be created using NN>&1 (redirecting stdout to /dev/fd/NN).
piping from multiple processes
The problem is the following: I have multiple command and I want to concatenate all the outputs. An obvious and easy way is to pipe all the outputs as input to the cat command. To do so, one must group all this commands together:
$ clear ; (ls /usr ; echo "foo bar" ; grep ntp /etc/passwd) | cat bin include info lib lib64 libexec local lost+found sbin share src var foo bar ntp:x:87:87:Network Time Protocol:/var/lib/ntp:/bin/false
$ cd /usr && ls -1 bin include info lib lib64 libexec local lost+found sbin share src var $ ls -1 | pee 'tail -1' 'head -1' var bin