6

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?

  • file <(command) says: /dev/fd/63: broken symbolic link to pipe:[10973768]' – Cyrus Jul 24 '14 at 19:53
  • Command substitution writes to the file /dev/fd/63 and then pipes this into the command. The problem is, is that this file is not seekable meaning it can only be read as a full file without random access. One of the main features of less is that it doesn't read the whole file at once, and so causes this error message.Using a text editor that reads the whole file at once will work. Etc Vi – user78605 Jul 24 '14 at 20:11
  • @Jidder what about piping to stdin? Isn't that not seekable as well? – Drew McGowen Jul 24 '14 at 20:21
  • No i dont think it is seekable, possibly i had misunderstood but i found this Programs that explicitly check the type of a file before opening it may refuse to work with process substitution, because the "file" resulting from process substitution is not a regular file. – user78605 Jul 24 '14 at 20:28
3

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.

  • 1
    I believe that you’re a bit confused on the nomenclature. <(command) is process substitution. Changing that to < <(command) is just making it complicated. – Scott Jul 25 '14 at 2:21
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.