11

Find command seems not to work at all. For example, I'm in a directory where there absolutely is file named index.php and I execute this:

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

I always get this no such file or directory error.

No matter what path I define, or what file I search for, I always get this error. I'm pretty sure that I'm overlooking something very simple. Can someone point out what I'm doing wrong?

[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 . output: https://gist.github.com/andrisp/f3adaf740548eead33da

[root@server htdocs]# find . -noleaf -name "index.php"
find: .: No such file or directory
20
  • What does ls -la|grep "index.php" say?
    – user80551
    Commented Jun 14, 2014 at 11:52
  • find . doesn't work either? What about ls -al?
    – Braiam
    Commented Jun 14, 2014 at 12:00
  • 1
    The fact that find . finds the . entry, then complains that it doesn't exist is curious. Seemingly this is a bug with find, which version are you using?
    – Graeme
    Commented Jun 14, 2014 at 14:28
  • 2
    Can you post the output of strace find . somewhere? Commented Jun 14, 2014 at 15:36
  • 1
    @mikeserv it's ext3, but i have enabled ACL on it without really knowing what I'm doing :), so it's probably the reason. Will try to disable it and see what happens
    – andris
    Commented Jun 17, 2014 at 20:28

8 Answers 8

2

According to your strace output, and I have no idea about the reason, the open() function prefix filenames with /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
1

I've see this happen on Mac when the directory is on removable media which has been removed and readded since the terminal window was opened. I can't explain why (probably has to do with information cached when the terminal session was started), but it was reproducible. Just restarted the terminal session and all was fine.

1
  • Similarly I'm seeing this on a mac where the current directory is getting updated by rsync.
    – Von
    Commented Jun 12, 2021 at 1:32
0

Try it with the absolute path like:

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

And as already mentioned above it might be that you do not have permissions. What happens if you:

ls . 

Does your shell know what to do with the dot?

0

I'm using an ancient version of SunOS. SunOS 4.1.3 to be exact. SMH.

The reason I was getting "no such file or directory" was because it was stumbling upon symbolic links.

I thought perhaps the permissions issue mentioned above was the cause, so I ran my command as root and still got it.

Looking at one of the files it stumbled upon, I saw that it was a symbolic link; so I tried adding -follow to the command. No joy.

I'm rusty with Unix scripting, so I'm exploring my options.

My original command:

find . -exec grep ai1212.pic {} \; -print

My updated command, having no such errors:

find . ! -type l -exec grep ai1212.pic {} \; -print

The '!' negates an option and 'l' is a symbolic link. I do not know if this holds within Linux or not.

-1

You might not have execution permission for your user for the directory you are searching from. Does it have read and execute permission?

-1

You can use

$ find ~/ -type f -name "MYFILE"

The best way to search for file or folder is :

  • updatedb (for updating system file index).

  • locate Myfile

1
  • Note that using updatedb and locate require that a package which provides both to be installed (e.g., mlocate).
    – HalosGhost
    Commented Jul 24, 2014 at 3:05
-1

I'm using Red Hat Enterprise Linux Server release 6.4 (Santiago). You could make sure you are using the right find either /usr/bin or /bin to make sure the find command is there. If you can not even do a man on find, try changing your shell to either /bin/ksh or /bin/bash. I have found that environment variables and paths can get confused once in awhile.

-1

As others have mentioned, using the full path to the find binary may help. It's possible find is aliased with additional flags on your system. Typing \find will prevent any aliases from being used as well. You can also use alias to view command aliases in your current shell session.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .