在目前目錄上使用 find 時出現“find: .: No such file or directory”

在目前目錄上使用 find 時出現“find: .: No such file or directory”

查找命令似乎根本不起作用。例如,我所在的目錄中絕對存在名為 index.php 的文件,並且我執行以下命令:

[root@server htdocs]# find . -name "index.php"
find: .: No such file or directory

我總是收到“沒有這樣的文件或目錄”錯誤。

無論我定義什麼路徑,或搜尋什麼文件,我總是會收到此錯誤。我很確定我忽略了一些非常簡單的事情。有人可以指出我做錯了什麼嗎?

[root@server htdocs]# pwd
/srv/www/htdocs
[root@server htdocs]# type -a find
find is /usr/bin/find
[root@server htdocs]# ls -la | grep index.php
-rw-rw-r--  1 andris users  413 Sep  1  2013 index.php
[root@server htdocs]# find . -name "index.php"
find: .: No such file or directory
[root@server htdocs]# find .
.
find: .: No such file or directory

[root@server htdocs]# stat .
  File: `.'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: ca00h/51712d    Inode: 155686      Links: 12
Access: (0775/drwxrwxr-x)  Uid: (  504/  andris)   Gid: (  100/   users)
Access: 2014-06-17 19:37:22.000000000 +0000
Modify: 2014-06-08 21:06:16.000000000 +0000
Change: 2014-06-08 21:06:16.000000000 +0000

[root@server htdocs]# find --version
GNU find version 4.2.27
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION SELINUX

strace find .輸出:https://gist.github.com/andrisp/f3adaf740548eead33da

[root@server htdocs]# find . -noleaf -name "index.php"
find: .: No such file or directory

答案1

根據您的strace輸出,我不知道原因,該open()函數的檔案名稱前綴為/proc/

open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 4
fcntl64(4, F_SETFD, FD_CLOEXEC) = 0
getdents64(4, /* 21 entries */, 32768) = 664
getgid32() = 0
stat64("/proc/index.php", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getgid32() = 0
stat64("/proc/.svn", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getgid32() = 0
stat64("/proc/init-dist.php", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getgid32() = 0
stat64("/proc/landing-page.html", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getgid32() = 0
[...]
stat64("/proc/js", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getgid32() = 0
stat64("/proc/extras", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getgid32() = 0
stat64("/proc/sitemaps", 0xbfc53bd0) = -1 ENOENT (No such file or directory)
getdents64(4, /* 0 entries */, 32768) = 0

答案2

我在 Mac 上看到過這種情況,當目錄位於可移動媒體上時,自從終端視窗打開以來,該媒體已被刪除和讀取。我無法解釋原因(可能與終端會話啟動時快取的資訊有關),但它是可重現的。剛剛重新啟動終端會話,一切都很好。

答案3

嘗試使用絕對路徑,例如:

   sudo find /where/your_file_is/located/ -iname "index.php"

正如上面已經提到的,您可能沒有權限。如果您出現以下情況,會發生什麼情況:

ls . 

你的 shell 知道如何處理這個點嗎?

答案4

您的使用者可能沒有對您正在搜尋的目錄的執行權限。是否具有讀取和執行權限?

相關內容