MacOS – find command just hangs on /dev/fd/*

macmacosterminal

Using sudo find has randomly stopped working for me. It used to work as expected but now just hangs forever and just says:

find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory

ls -lOeR /dev/fd/* says that /dev/fd/0, /dev/fd/1, and /dev/fd/2 are character special files and that 3 and 4 are directories, all owned by root.

It then says:

/dev/fd//3:
ls: 3: Not a directory
ls: 4: directory causes a cycle

/dev/fd//3 has two slashes before the three which I don't understand either. Does anyone know what is going on with find and why this randomly started. I'm not able to use find anymore and had previously never even heard of /dev/fd.

Best Answer

Find has not randomly stopped working, but is functioning as it should. The problem is that you're running a command that you do not fully understand. It sounds likely that you do not at all want to have find looking through your /dev directory.

The reason you get different results with find and ls is that the /dev/fd directory does not represent a physical directory on disk. Instead it is a virtual file system that contains the file descriptors that the process looking at /dev/fd have obtained.

This means that ls sees one /dev/fd while find sees another (and similar for all other running processes).

In essence you want to take a look at your find command and make sure it is constructed correctly for the task you want to perform. If you want to ask about that on SO, please remember to include the full command you're trying to run as well as what you're expecting that command to do for you.