To locate files on my computer that have a given string, I execute the following command in the root directory using a Unix bash shell:
bash$ sudo find . -name file-name-to-be-searched
I then get a list of files but also the following:
find: ./dev/fd/3: Not a directory find: ./dev/fd/4: Not a directory
This is puzzling because there is also ./dev/fd/5
which does not appear listed and for all three of them, when I do:
bash$ cd ./dev/fd bash$ cat 3
(or 4 or 5)
I get:
Bad file descriptor
Bash gives the same message with:
bash$ cd 3
This is the contents of the directory:
bash$ pwd /dev/fd bash$ ls -l total 0 crw--w---- 1 bro tty 16, 5 Oct 26 02:54 0 crw--w---- 1 bro tty 16, 5 Oct 26 02:54 1 crw--w---- 1 bro tty 16, 5 Oct 26 02:54 2 dr--r--r-- 1 root wheel 0 Oct 21 09:15 3 dr--r--r-- 1 root wheel 0 Oct 21 09:15 4 dr--r--r-- 1 root wheel 0 Oct 21 09:15 5
I would like to know why I get this behavior, why I don't see a similar message for file ./dev/fd/5
and if this may be an indicator that I am not searching the entire directory structure. If there is some sort of corrupted file that this signals, is there a way not to list it?
To address the last part of the question, as suggested by Marc 's comment (thank you,), adding 2> /dev/null
gets rid of the error messages:
bash$ sudo find. -name file-name-to-be-searched 2> /dev/null
However, it leaves us a bit in the dark as to why there is no error message for the file descriptor /dev/fd/5
and its possible impacts in the execution of find
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.