What does all this stuff mean?
/proc is a filesystem through which the kernel reports various information to processes. It's mostly for information about processes, hence the name “proc[esses]”. For each running process, there's a subdirectory
<PID> is the process ID.
/proc/self is a “magic” symbolic link that always points to the process that's accessing
/proc/self/fd reports the files opened by a process. Each entry is a “magic” symbolic link whose name is the file descriptor and whose target is the open file. It's magic in the sense that the link actually points to the file itself, even if the file name obtained by calling
readlink is not a valid file name, which happens, for example, with files that don't have a name (such as anonymous pipes and sockets), and with deleted files.
lrwx------ 1 username username 64 Nov 8 19:01 0 -> /dev/pts/6
lrwx------ 1 username username 64 Nov 8 19:01 1 -> /dev/pts/6
lrwx------ 1 username username 64 Nov 8 19:01 2 -> /dev/pts/6
lrwx------ 1 username username 64 Nov 8 19:01 3 -> 'socket:'
lr-x------ 1 username username 64 Nov 8 19:01 4 -> /proc/29512/fd/
How do floppy disks work here?
No floppy disks are involved. The abbreviation “fd” stands for file descriptor.
/dev/pts/6, and why do
2 all point to it?
2 are the three standard streams) that all programs expect to find: standard input (stdin), standard output (stdout) and standard error (stderr). These streams are defined by their number: stdin is file descriptor 0 by definition, and its conventional role is to receive user input or input data, and likewise for stdout (1, user output or output data) and stderr (2, error messages).
/dev/pts/6 is a terminal. It's the file that processes use to read input from, and write output to, that particular terminal. When you run a program “normally” in a terminal, stdin, stdout and stderr are all connected to the terminal.
It's a socket. File descriptor 3 has no standard role, so it's specific to some software you're using, maybe your terminal emulator. You can see what's on the other end of the socket if you're curious.
When you run
ls /proc/self/fd/, the
ls program opens
/proc/self/fd to read its contents. Since file descriptors 0 to 3 are already open when
ls starts, and
open uses the first available file descriptor,
/proc/self/fd ends up being open on file descriptor 4. It appears with the PID because the kernel doesn't keep track of accesses through
/proc/self internally: it remembers them as a particular process's
/proc directory, which it then prints out using the correct PID. (With PID namespaces, that PID, and hence the path, can be different depending on which process is looking.)
What is the historical use of and description for
It's useful when programs need a file name and you want to refer to a file that's already open. It's a generalization of
/dev/stderr which are equivalent to
/dev/fd/2 respectively (and existed before the more general
/dev/fd appeared). It's available on many unix variants.