ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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.
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*
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!
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.
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.
It's still a problem with the shell expanding the unquoted wildcard. There are four cases to consider:
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.