2 ms·
These are also available as /dev/std{in,out,err}; the names of which are a little more self documenting :) $ ls -l /dev/fd /dev/std* | column -t lrwxrw
by LukeShu 12y ago
These are also available as /dev/std{in,out,err}; the names of which are a little more self documenting :)
$ ls -l /dev/fd /dev/std* | column -t
lrwxrwxrwx 1 root root 13 Jun 27 16:32 /dev/fd -> /proc/self/fd
lrwxrwxrwx 1 root root 15 Jun 27 16:32 /dev/stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root 15 Jun 27 16:32 /dev/stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root 15 Jun 27 16:32 /dev/stdout -> /proc/self/fd/1
You can even access the file descriptors of other processes with /proc/${pid}/fd/; which is handy for (say) un-deleting a file that a process still has open.
Another handy one is "process substitution" which lets you do the same thing with multiple streams by creating new file descriptors, and automatically turning them into /dev/fd/* paths:
someCommand <(echo "contents of file 1") <(echo "contents of file 2")
which is somewhat explained by:
$ echo someCommand <(echo "contents of file 1") <(echo "contents of file 2")
someCommand /dev/fd/63 /dev/fd/62
- toddkaufmann 12y ago"process substitution" is one of the new useful things I learned this year (switched to bash from csh over 20 years ago). /proc/${pid}/fd/ is very useful for forensic purposes when you find some malware running that deleted itself and/or config files but still has a handle open to them.