Interview Prep/Linux/Processes, Signals & systemd

What is a file descriptor? What are 0, 1 and 2?

BeginnerConceptProcesses, Signals & systemd
Answer

A file descriptor is an integer index into a process's table of open files, sockets and pipes. 0 is stdin, 1 is stdout, 2 is stderr. New opens get the lowest free number.

cmd > out.log 2>&1     # both streams to file
cmd 2>/dev/null        # drop errors
cmd &> out.log         # bash shorthand

Order matters: 2>&1 > file sends stderr to the terminal.

All Linux questions Roadmap: Linux

More on Processes, Signals & systemd