LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-18-2018, 03:07 AM   #1
darksaurian
Member
 
Registered: Jun 2010
Location: USA
Distribution: Fedora Xfce spin
Posts: 193

Rep: Reputation: 27
can't understand find output


I have a webpage that used to work and then it stopped working so I'm trying to figure it out. Nevermind all that and nevermind anything I did wrong in the output below. The only thing I'm asking is why is my find statement saying ANYTHING about Eskimo.cgi? There's nothing about Eskimo.cgi in the statement I typed. There actually is an Eskimo.cgi in the current directory but why is my find statement talking about it?

Code:
darksaurian@whatever.com [~/public_html]# find ./sharks/explorations/Eskimo/AQUASANS -type f -iname *.*
find: paths must precede expression: Eskimo.cgi
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
darksaurian@whatever.com [~/public_html]#
 
Old 05-18-2018, 04:10 AM   #2
Honest Abe
Member
 
Registered: May 2018
Distribution: CentOS
Posts: 43

Rep: Reputation: Disabled
because "-iname *.*" tells it to match every file with every extension , irrespective of case.

from man page -
Code:
       -iname pattern
              Like -name, but the match is case insensitive.  For example,
              the patterns `fo*' and `F??' match the file names `Foo',
              `FOO', `foo', `fOo', etc.  The pattern `*foo*` will also match
              a file called '.foobar'.
Also, you are using wildcard expansion, which basically expands to -

"find PATH TYPE -iname file1.extension1 file2.extension2 .... fileN.extensionN" - hence the systax error (paths must precede expression: Eskimo.cgi).
Either drop the -iname or put '*.*' [notice the single quotes]

iname is useful if you remember a part of the file's name. If you indeed want to list all files, drop the -iname and it'll still work.

Last edited by Honest Abe; 05-18-2018 at 04:12 AM.
 
Old 05-18-2018, 04:17 AM   #3
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,668

Rep: Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997
Go read the man entry.

Quote:
Please note that you should quote patterns as a matter of course, otherwise the shell will expand any wildcard characters in them.
So enclose your matching pattern in quotes so that it's -iname "*.*"
 
Old 05-18-2018, 05:08 AM   #4
darksaurian
Member
 
Registered: Jun 2010
Location: USA
Distribution: Fedora Xfce spin
Posts: 193

Original Poster
Rep: Reputation: 27
Oh. Sorry.

It seemed really bizarre to me because if I changed it to
Code:
find ./sharks/explorations/CARROT/AQUASANS -type f -iname *.*
then it would have absolutely nothing to do with Eskimo anything and it would still say "find: paths must precede expression: Eskimo.cgi" and I was convinced it had something to do with the fact that Eskimo.cgi was the cgi script I had ran moments before out of the dozen cgi scripts I have. I especially thought this because I have several files and scripts that start with the letter 'a' or other letters that come before "Eskimo.cgi" However! "Eskimo" had a capital E and was actually the first file in that directory and that is the only reason that's the file "find" was talking about.

Don't worry, no one is dumb enough to pay me to program.
 
Old 05-18-2018, 05:12 AM   #5
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 3,064
Blog Entries: 3

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
If you wrap the *.* in quotes so it is "*.*" or '*.*' that will keep it from being interpreted by the shell before getting passed to find. Try a simpler variant and compare these two:

Code:
ls *
ls "*"
You'll see that the first variant processes the * and replaces it before getting passed to ls. The second variant passes * as an unchanged, literal string.
 
Old 05-18-2018, 06:53 AM   #6
darksaurian
Member
 
Registered: Jun 2010
Location: USA
Distribution: Fedora Xfce spin
Posts: 193

Original Poster
Rep: Reputation: 27
Okay. My first question was dumb. But now I have a good one. Check it out. You're gonna think it's a dumb question at first but it gets good towards the end.

I have two files in this directory that end in .abc
Code:
darksaurian@whatever.com [~/public_html/sharks/explorations/Eskimo/AQUASANS]# ls
./  ../  1234.abc  5678.abc
darksaurian@whatever.com [~/public_html/sharks/explorations/Eskimo/AQUASANS]#
Now when I look for 123* it finds the one that starts with 123*
Code:
darksaurian@whatever.com [~/public_html]# find ./sharks/explorations/Eskimo/AQUASANS -type f -iname 123*
./sharks/explorations/Eskimo/AQUASANS/1234.abc
darksaurian@whatever.com [~/public_html]#
When I look (incorrectly) for any that end it .abc it finds nothing.
Code:
darksaurian@whatever.com [~/public_html]# find ./sharks/explorations/Eskimo/AQUASANS -type f -iname *.abc
darksaurian@whatever.com [~/public_html]#
When I look (with quotes) for any that end it .abc it finds both files
Code:
darksaurian@whatever.com [~/public_html]# find ./sharks/explorations/Eskimo/AQUASANS -type f -iname "*.abc"
./sharks/explorations/Eskimo/AQUASANS/1234.abc
./sharks/explorations/Eskimo/AQUASANS/5678.abc
darksaurian@whatever.com [~/public_html]#
Okay fine. But here's what I don't get. My cgi script had been using that incorrect find line for the past three months or whatever and it always worked. A couple days ago I checked and it failed to list the files it used to list. Just now I put the quotes there like you guys told me I needed to do and it works again. Why did it work for the past three months? Did the the server my webpage runs on get its kernel updated or something? Plus I have other cgi scripts that do the exact same thing, they have that exact same line without the quotes and they still work!

This still works!
Code:
find ./sharks/explorations/Fish/AQUASANS -type f -iname *.atx | xargs -n 1 echo > $TempFile2
This used to work but now it doesn't:
Code:
find ./sharks/explorations/Eskimo/AQUASANS -type f -iname *.abc | xargs -n 1 echo > $TempFile2
So I changed it to this and now it works again:
Code:
find ./sharks/explorations/Eskimo/AQUASANS -type f -iname "*.abc" | xargs -n 1 echo > $TempFile2
Again, it worked for months. I never touched it. Then one day it stopped working so just now I put the quotes in and it works again. But the script without the quotes still works. What the hell?

Last edited by darksaurian; 05-18-2018 at 07:38 AM.
 
Old 05-18-2018, 07:01 AM   #7
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 3,064
Blog Entries: 3

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
It probably worked because the pertinent directory was empty and started to fail once there were files.
 
Old 05-18-2018, 07:17 AM   #8
darksaurian
Member
 
Registered: Jun 2010
Location: USA
Distribution: Fedora Xfce spin
Posts: 193

Original Poster
Rep: Reputation: 27
No. The files were always there. I didn't add or remove any. It just stopped working one day. Here, look, I did this just now. I created that boner directory and put those two files in it and then I did all the lines you see below. I've been fudging my output for the sake of anonymity but this cut and paste is exact and I did it just now. The only part I changed was darksaurian@whatever.com

Code:
darksaurian@whatever.com [~/public_html]# 
darksaurian@whatever.com [~/public_html]# cd boner                         
darksaurian@whatever.com [~/public_html/boner]# ls
./  ../  asdf.ard  qwer.asd
darksaurian@whatever.com [~/public_html/boner]# cd ..
darksaurian@whatever.com [~/public_html]# find ./boner -type f -iname *.asd
./boner/qwer.asd
darksaurian@whatever.com [~/public_html]# find ./boner -type f -iname *.ard
darksaurian@whatever.com [~/public_html]# find ./boner -type f -iname "*.asd"
./boner/qwer.asd
darksaurian@whatever.com [~/public_html]# find ./boner -type f -iname "*.ard"
./boner/asdf.ard
darksaurian@whatever.com [~/public_html]#
It's always been .ard and .asd if that helps. I made up the abc and atx extensions.

I have to put .ard in quotes but I don't have to put .asd in quotes! And on top of that for the past few months I never had to put .ard in quotes. This just happened recently. This is bizarre.
 
Old 05-18-2018, 07:32 AM   #9
darksaurian
Member
 
Registered: Jun 2010
Location: USA
Distribution: Fedora Xfce spin
Posts: 193

Original Poster
Rep: Reputation: 27
If I do the exact same thing on my Fedora computer I don't need the quotes at all:
Code:
[laconiclizard@localhost Desktop]$ cd boner
[laconiclizard@localhost boner]$ ls
asdf.ard  qwer.asd
[darksaurian@localhost boner]$ cd ..
[darksaurian@localhost Desktop]$ find ./boner -type f -iname *.asd
./boner/qwer.asd
[darksaurian@localhost Desktop]$ find ./boner -type f -iname *.ard
./boner/asdf.ard
[darksaurian@localhost Desktop]$ find ./boner -type f -iname "*.ard"
./boner/asdf.ard
[darksaurian@localhost Desktop]$ find ./boner -type f -iname "*.asd"
./boner/qwer.asd
[darksaurian@localhost Desktop]$
It's only on whatever system my website is on:
Code:
darksaurian@whatever.com [~/public_html]# 
darksaurian@whatever.com [~/public_html]# cat /proc/version
Linux version 3.10.0-693.17.1.2.ELK.el6.x86_64 (root@bluerock1.bluehost.com) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-15) (GCC) ) #1 SMP Thu Feb 8 23:35:45 MST 2018
darksaurian@whatever.com [~/public_html]#
 
Old 05-18-2018, 08:23 AM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,895

Rep: Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679Reputation: 1679
It's still a problem with the shell expanding the unquoted wildcard. There are four cases to consider:
  1. If the wildcard doesn't match anything in the current directory, then the shell will pass along the unchanged wildcard just as though you had quoted it, and find will do what you expected.
  2. If the wildcard matches multiple files in the current directory, then the shell will pass all those filenames, and find will complain "paths must precede expression" because of the extra arguments.
  3. If the wildcard matches exactly one file in the current directory and there is no file with that exact name in ./boner, then find will find nothing.
  4. If the wildcard matches exactly one file in the current directory and there is a file with that same name in ./boner, then find will find that name and no others.
It's all a matter of what the wildcard does, or does not, match in the current directory, and that can make the result seem very inconsistent. The answer is to always quote characters that are special to the shell if you want those characters reliably passed unchanged to the command.

Last edited by rknichols; 05-18-2018 at 08:25 AM.
 
1 members found this post helpful.
Old 05-18-2018, 08:36 AM   #11
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 10,672

Rep: Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175
you might want to execute set -xv before executing that find command.
You will see how shell will preprocess the command before executing that find - and what are the real parameters passed to find.
 
1 members found this post helpful.
Old 05-18-2018, 08:01 PM   #12
darksaurian
Member
 
Registered: Jun 2010
Location: USA
Distribution: Fedora Xfce spin
Posts: 193

Original Poster
Rep: Reputation: 27
Thanks all. Sorry. I only "program" like twice a year. Inconsistent results are baffling to me.
 
Old 05-19-2018, 09:55 AM   #13
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 10,672

Rep: Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175Reputation: 3175
Quote:
Originally Posted by darksaurian View Post
Inconsistent results are baffling to me.
I'm sorry, but usually that means incorrect logic, bad implementation. The computer will do exactly what was requested/implemented.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to understand lsusb Output? ultra_reader Linux - Hardware 9 04-02-2018 05:22 PM
[SOLVED] How to understand the output of tcpdump? luofeiyu Linux - Networking 4 08-23-2015 07:49 PM
[SOLVED] Unable to understand ps output. pinga123 Linux - Newbie 6 05-03-2011 11:20 AM
how to understand valgrind output? santoshturamari Linux - Newbie 0 11-04-2008 04:57 AM
cannot understand some dmesg output ninadb Slackware 8 06-29-2005 04:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration