Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the 'find' command fail without an error?

Tags:

linux

find

NOTE It seems I have forget to mention that this only happens after a reboot. Once booted, it doesn't matter if I run the command 5 mins after boot or 3 days after boot. But once find is run, it will always find it (even after 5 mins or 3 days).

I have a Raspberry Pi 3 running Linux 4.9.17-v7+. I don't know why this is happening, but everytime I log into the machine and try to find a known png file, the prompt returns as if there are no result. Knowing that the file exists, I run the same command again (up arrow key) and it returns with the proper results.

How can I get 2 different results (or inconsistant results) with the find command? Might there be a package I'm missing?

Proof of the file's existance:

me@here:~ $ ls -la /opt/retropie/supplementary/splashscreen/retropie-default.png
-rw-r--r-- 1 root root 1168926 Mar 30 19:51 ls -la /opt/retropie/supplementary/splashscreen/retropie-default.png

But when I run the find command, the prompt returns with no results or errors:

me@here:~ $ sudo find / -name *default.png
me@here:~ $

If I run the find command again, I get these results:

me@here:~ $ sudo find / -name *default.png
/opt/retropie/supplementary/splashscreen/retropie-default.png
me@here:~ $

What am I doing wrong? Am I missing a package? Has a program gone corrupt? When I'm searching for something and I get no results, how do I know if it exists or not? Please help me!

UPDATE 1: Comment request.

Running the command with the -name argument quoted:

me@here:~ $ sudo find / -name '*default.png'
me@here:~ $ sudo find / -name '*default.png'
/opt/retropie/supplementary/splashscreen/retropie-default.png
me@here:~ $

UPDATE 2: Taking the sd card to another computer, mounting it and doing the search again sudo find /mnt/flash -name '*default.png' produced the correct results. So it has to be either the OS or possibly a hardware problem.

UPDATE 3: I loaded a fresh OS onto the Raspberry Pi 3 and took the offending 'sd card/OS' and mounted it on the Raspberry Pi 3. This was to see if it might be a hardware error. sudo find /mnt/flash -name '*default.png' produced the correct results. So it has to be the OS.

Originally, I took RetroPie v4.2, stopped it from automatically running. Took my entertainment software and compiled it. Set it up to run on boot along with lirc. An option in the entertainment software is to run Emulationstation (the command you comment out to stop the automatic running of the emulation software on boot). It all works. So I don't know what would cause this issue.

As far as I know, the /opt directory that the file is contained in is no different from any other.

UPDATE 4: Ok, before searching for '*default.png' I did sudo find / -name 'hostname' and it came back with correct results. Then I ran sudo find / -name '*default' and it found it. So only the first find command might fail. Subsequent ones all seem to work.

UPDATE 5: I was able to locate another OS where the first find doesn't always work. I have another Raspberry Pi 1 Model B that is running Arch Linux 4.1.7-2-ARCH. It doesn't contain the png I've been searching for, but I searched for it anyway.

me@there:~ $ sudo find / -name '*default.png'
me@there:~ $ sudo find / -name '*default.png'
/usr/share/icons/Adwaita/256x256/status/avatar-default.png
/usr/share/icons/Adwaita/8x8/emblems/emblem-default.png
/usr/share/icons/Adwaita/16x16/emblems/emblem-default.png
/usr/share/icons/Adwaita/16x16/status/avatar-default.png
/usr/share/icons/Adwaita/22x22/emblems/emblem-default.png
/usr/share/icons/Adwaita/22x22/status/avatar-default.png
/usr/share/icons/Adwaita/32x32/emblems/emblem-default.png
/usr/share/icons/Adwaita/32x32/status/avatar-default.png
/usr/share/icons/Adwaita/48x48/emblems/emblem-default.png
/usr/share/icons/Adwaita/48x48/status/avatar-default.png
/usr/share/icons/Adwaita/24x24/emblems/emblem-default.png
/usr/share/icons/Adwaita/24x24/status/avatar-default.png
/usr/share/gtk-doc/html/gtk3/window-default.png
me@there:~ $ 

So 2 different OS's and 2 different Raspberry Pi's have the same problem. I've tested this on my Banana Pi and the result are correct the first time.

UPDATE 6: Ok, updates on some comments. Yes, the file retropie-default.png is on the root directory, and there are no autofs/unionfs anywhere on the system.

sudo find /opt/retropie/supplementary/splashscreen/ -name '*default.png' doesn't behave the same way and does produce the correct results.

Running sudo date twice does produce the correct results.

Please read to note at the beginning of this post as I forgot one important point.

I'll be running strace later today.

UPDATE 7: Listing the directory before the find command still produces that same results.

me@here:~ $ ls /opt/retropie/supplementary/splashscreen/
LICENSE                             retropie-2015-carbon-video.mp4
README.md                           retropie-2015.png
retropie-2013.png                   retropie-default-16x10.png
retropie-2014.png                   retropie-default-4x3.png
retropie-2015-4x3.png               retropie-default.png
retropie-2015-carbon-video-4x3.mp4
me@here:~ $ sudo find / -name '*2013.png'
me@here:~ $ sudo find / -name '*2013.png'
/opt/retropie/supplementary/splashscreen/retropie-2013.png
me@here:~ $

UPDATE 8: sudo strace -o log1 find / -name '*default.png' and then sudo strace -o log2 find / -name '*default.png' These log files are huge. What is it that I'm looking for in it? Doing cat logn|grep 'x' where x is 'warning, Warning, WARNING, error, Error, ERROR. What else should I check for? There is a size difference in the log files log1 = 9.9M and log2 = 13 M

I did notice at the end of both log files that there is a different command in log2. munmap(0x76f31000, 4096) is not in log1. Maybe this is where the failure lies?

like image 634
Deanie Avatar asked Mar 30 '17 20:03

Deanie


People also ask

How do I get rid of errors in find command?

use 2>/dev/null. The 2>/dev/null at the end of the find command tells your shell to redirect the standard error messages to /dev/null, so you won't see them on screen. “/dev/null” is a virtual device file, Whatever you write to “/dev/null” will be discarded by the system.

How does the find command work?

The find command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments. find command can be used in a variety of conditions like you can find files by permissions, users, groups, file types, date, size, and other possible criteria.

What does find return if nothing is found bash?

Hi, the find command will only return non zero value on error, so it will return 0 if it find or not file. A solution could be to pipe the output to grep -q who will return non zero if not found.

Why do we use \; in find command?

$ find. Search for a file by the name abc. txt below the current directory, and prompt the user to delete each match. Note that the “{}” string is substituted by the actual file name while running and that the “\;” string is used to terminate the command to be executed.


1 Answers

You can see 'find' manpage to get the answer. If you want to use regex in your command, you must quote the regex. Your command should be sudo find / -name \*default.png or sudo find / -name '*default.png'

Manpage Reference Below

NON-BUGS

“paths must precede expression” error message

$ find . -name *.c -print find: paths must precede expression Usage: find [-H] [-L] [-P] [-Olevel] [-D ... [path...] [expression]

This happens because *.c has been expanded by the shell resulting in find actually receiving a command line like this (If there are frcode.c locate.c word_io.c files in . folder):

find . -name frcode.c locate.c word_io.c -print

That command is of course not going to work. Instead of doing things this way, you should enclose the pattern in quotes or escape the wildcard:

$ find . -name '*.c' -print $ find . -name \*.c -print

like image 123
Ryan.Shi Avatar answered Oct 25 '22 23:10

Ryan.Shi