简体   繁体   English

查找 unix 命令给出“不是目录”错误消息

[英]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.

相关问题 Unix查找命令目录提示 - Unix find command directory hints Unix查找命令忽略丢失的文件或目录 - Unix Find Command Ignoring Missing File or Directory 哪个命令给出错误“环境:节点:没有这样的文件或目录” - which command gives error "env: node: No such file or directory" 尝试创建钥匙串“ UNIX [无此文件或目录]时出错 - Error trying to create a keychain "UNIX[No such file or directory] Selenium 在 Mac 上给出“selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary” - Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac OSX / Unix find命令来查找Dropbox的冲突副本 - OSX / Unix find command to find Dropbox' conflicted copies 用于Java程序的UNIX命令,从另一个目录输入文本 - UNIX Command for Java program, input text from another directory 如何从命令行更改Linux / Unix中的目录结构? - How to change directory structure in Linux/Unix from Command Line? 在OS X中创建到目录的硬链接的Unix命令是什么? - What is the Unix command to create a hardlink to a directory in OS X? cd Desktop 在终端中给出错误没有这样的文件/目录 - cd Desktop gives an error no such file/ directory in terminal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM