"command | less" vs "less <(command)"

A common “idiom” for viewing large amounts of command output is to pipe it to less, via command | less. However, it’s also possible (perhaps only in bash, haven’t tested in other shells) to use the less <(command) syntax, but less tends to complain /dev/fd/63 is not a regular file. After poking around in /proc/*/fd, I see that in both cases, it’s reading from a pipe. The only difference is that in the first case, it’s stdin being redirected. In the second case, it’s getting /dev/fd/63 as a file name. Does less somehow “ignore” the regular file check when reading from stdin? Also, how does it determine that /dev/fd/63 isn’t a regular file, even if the contents are text?

Asked By: Drew McGowen


less tends to complain /dev/fd/63 is not a regular file

The solution to that, under GNU less at least, is the use of the -f option:

less -f <(command)

Under normal circumstances, less will not open non-regular files (stdin excepted, obviously). This is for your protection. -f forces non-regular files to be opened.

Answered By: John1024

less normally refuses to open non regular files like pipes or also binaries. You can use the -f operator to force less to open non regular files:

less -f <(command)

Another approach is to use process substitution:

less < <(command)

This causes the pipe that was created with <() to act as standard input (STDIN) for less.

Answered By: chaos