File descriptors

Moving file descriptors around

copy stdout into new file descriptor 20:

exec 20>&1

echo to newly created fd 20:

echo foo >&20

Delete fd 1

exec >&-

OR

exec 1>&-

Delete fd 2

exec 2>&-

List file descriptors of PID 42:

ls -l /proc/42/fd

Can also be combined with the special variable $$:

ls -l /proc/$$/fd