[英]Find unix command gives “Not a directory” error message
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:要在我的计算机上找到具有给定字符串的文件,我使用 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:这令人费解,因为还有
./dev/fd/5
没有出现在列表中,对于所有三个,当我这样做时:
bash$ cd ./dev/fd bash$ cat 3
(or 4 or 5) (或 4 个或 5 个)
I get:我得到:
Bad file descriptor
Bash gives the same message with: Bash 给出了相同的消息:
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.我想知道为什么我会出现这种行为,为什么我没有看到文件
./dev/fd/5
的类似消息,以及这是否表明我没有搜索整个目录结构。 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:为了解决问题的最后一部分,正如Marc的评论(谢谢)所建议的那样,添加
2> /dev/null
可以消除错误消息:
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
.然而,它让我们有点不知所措,为什么文件描述符
/dev/fd/5
没有错误消息,以及它对find
执行的可能影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.