LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-04-2011, 11:52 PM   #1
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Rep: Reputation: 39
strange behavior of find


Ok I used find as follows

Quote:
find / -name vmware*
Result I get is
Quote:
/root/vmware-converter-distrib
but I have in /etc many scripts which are related to vmware.
So why did find fail to find all those.

If I go to /etc/ and do

Quote:
find ./ -name vmware*
I do get the files here how ever as shown above when I use

/ (root directory) and not ./

I do not get the desired output.

I am using find as root and I was in $HOME.So why did find not give me the desired result?

How ever when I did
Quote:
cd /
and went to / and used

Quote:
find / -name vmware*
I did get the desired result
Quote:
/root/vmware-converter-distrib
/root/vmware-converter-distrib/bin/vmware-uninstall-converter.pl
/root/vmware-converter-distrib/system_etc/init.d/vmware-converter
/root/vmware-converter-distrib/lib/share/vmware-converter.desktop
/root/vmware-converter-distrib/lib/share/vmware-converter.png
/root/vmware-converter-distrib/lib/client/bin/vmware-converter-client
/root/vmware-converter-distrib/lib/server/bin/vmware-converter-agent
/root/vmware-converter-distrib/lib/server/bin/vmware-ntfs
/root/vmware-converter-distrib/lib/server/bin/vmware-converter-server
/root/vmware-converter-distrib/lib/server/vmware_drivers.cab
/root/vmware-converter-distrib/lib/server/configurator/pam.d/vmware-converter
/root/vmware-converter-distrib/lib/server/pkg/vmware-sysinfo-lin64.tar.gz
/root/vmware-converter-distrib/lib/server/pkg/vmware-sysinfo-lin32.tar.gz
/root/vmware-converter-distrib/lib/server/vmware-tools
/root/vmware-converter-distrib/lib/server/vmware-converter
/root/vmware-converter-distrib/vmware-install.pl
/usr/src/linux-headers-2.6.32-21/arch/x86/include/asm/vmware.h
/usr/src/linux-headers-2.6.32-21-server/include/config/vmware
/usr/share/pyshared/VMBuilder/plugins/vmware
/usr/share/app-install/desktop/vmware-view.desktop
/usr/share/app-install/desktop/vmware-user.desktop
/usr/share/app-install/icons/vmware-view.png
/usr/lib/python2.6/dist-packages/VMBuilder/plugins/vmware
/etc/vmbuilder/vmware
/etc/vmbuilder/vmware/vmware.tmpl
/etc/vmware-converter
But why did it not showed this result when I was in $HOME of root and used find as mentioned?

Last edited by tkmsr; 01-04-2011 at 11:55 PM.
 
Old 01-05-2011, 03:07 AM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hello tkmsr,

do you have any aliases which may change the behaviour of the find command. You may issue the command "alias" in order to list all available aliases.

With which distribution did you experience this issue? And do you remember that it worked as expected once before?

Markus
 
Old 01-05-2011, 03:14 AM   #3
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Arrow

Try
Code:
sudo find / -iname '*vmware*'

Last edited by Mr. Alex; 01-05-2011 at 03:16 AM.
 
1 members found this post helpful.
Old 01-05-2011, 03:22 AM   #4
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by markush View Post
Hello tkmsr,

do you have any aliases which may change the behaviour of the find command. You may issue the command "alias" in order to list all available aliases.

With which distribution did you experience this issue? And do you remember that it worked as expected once before?

Markus
Markush I noticed this on Ubuntu server 10.04 bit.I regularly use find on my Ubuntu desktop which is 10.04 64 bit and different than.There are no aliases.So find is not new thing for me but this behavior is surely strange enough for me.I want to understand why this happened.

Last edited by tkmsr; 01-05-2011 at 03:25 AM.
 
Old 01-05-2011, 03:23 AM   #5
mark_alfred
Senior Member
 
Registered: Jul 2003
Location: Toronto, Ontario, Canada
Distribution: Ubuntu Linux 16.04, Debian 10, LineageOS 14.1
Posts: 1,572

Rep: Reputation: 210Reputation: 210Reputation: 210
That's weird. It really should have worked. Anyway, I feel the find command is quite tedious. Instead, run "updatedb" as root/sudo, and then use the "locate" command.
 
1 members found this post helpful.
Old 01-05-2011, 04:25 AM   #6
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Hi,

I think this is a globbing issue. When you use
Code:
find / -name vmware*
from within your $HOME directory then vmware* is first expanded by bash's globbing mechanism and then passed to 'find'. So if you have 'vmware-converter-distrib' then vmware* is expanded to that value and 'find' sees
Code:
find / -name vmware-converter-distrib
If the globbing mechanism, however, does not find a match then it passes vmware* to find. Then 'find' performs its own pattern matching on the asterisk. If you want to use wildcards with 'find' then you should single- or double-quote the pattern or escape the wildcard like vmware\*.

To further explore this create two dummy files:
Code:
touch file{1,2}
Now do try searching for them while in the same folder:
Code:
find . -name file*
This will result in an error since file* is now expanded to
file1 file2
So this is what the command looks like when it is executed:
Code:
find . -name file1 file2
When you execute the command in the parent folder then 'find' will work as expected, i.e. if the parent folder does not contain any files that will be matched by bash's globbing mechanism.
 
3 members found this post helpful.
Old 01-05-2011, 04:40 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
As usual, crts is on the money. Quotes will easily produce desired results
 
1 members found this post helpful.
Old 01-05-2011, 08:14 AM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
You have to quote your wildcards so that they are passed to find instead of being interpreted by BASH first.
 
1 members found this post helpful.
Old 01-05-2011, 08:19 AM   #9
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by MTK358 View Post
You have to quote your wildcards so that they are passed to find instead of being interpreted by BASH first.
I do not agree with you because I tried the same thing on a Ubuntu desktop edition (10.04 64 bit) and I used wildcard as I posted above and I see things working well without a problem.I did searched the way I expected in all subdirectories.
I feel some thing is seriously wrong with find on Ubuntu server edition.
 
0 members found this post helpful.
Old 01-05-2011, 08:25 AM   #10
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by tkmsr View Post
I do not agree with you because I tried the same thing on a Ubuntu desktop edition (10.04 64 bit) and I used wildcard as I posted above and I see things working well without a problem.I did searched the way I expected in all subdirectories.
I feel some thing is seriously wrong with find on Ubuntu server edition.
Did you also take your starting directory into consideration? I.e. were there any files that could have been matched and expanded by bash before they were passed to 'find'?
Also, could you check and post your shell options?

[EDIT]
I am specifically interested in the output of
echo $SHELLOPTS

Did you accidentally toggle the 'noglob' flag?

Last edited by crts; 01-05-2011 at 08:32 AM.
 
1 members found this post helpful.
Old 01-05-2011, 08:35 AM   #11
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by crts View Post
Did you also take your starting directory into consideration? I.e. were there any files that could have been matched and expanded by bash before they were passed to 'find'?
Also, could you check and post your shell options?
Ok I am referring to the desktop edition where you asked for the results.
I am currently in a directory pwd shows
Quote:
/mnt/jaunty/home/tkmsr/Work/system_administration
in this I have following
Code:
find.txt  links\ to\ block.txt  links_to_practise.txt  ssh\ blocking.txt  vmware_conversion.txt
I did
Code:
sudo find / -name links_to_*
from above directory
result
Quote:
/mnt/jaunty/home/tkmsr/Work/system_administration/links_to_practise.txt
/tmp/links_to_practise.txt
I had deliberately copied
links_to_practise.txt in /tmp to understand the problem I reported in this thread and results differ in the behaviour on server edition and desktop edition of Ubuntu 10.04 64 bit.
 
Old 01-05-2011, 08:43 AM   #12
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by tkmsr View Post
I am currently in a directory pwd shows
Code:
/mnt/jaunty/home/tkmsr/Work/system_administration
in this I have following
Code:
find.txt  links\ to\ block.txt  links_to_practise.txt  ssh\ blocking.txt  vmware_conversion.txt
I did
Code:
sudo find / -name links_to_*
from above directory
result
Code:
/mnt/jaunty/home/tkmsr/Work/system_administration/links_to_practise.txt
/tmp/links_to_practise.txt
I don't see anything odd in that behavior. The asterisk can only expand to 'links_to_practise.txt' and nothing else. Create another file in the same directory and name it
'links_to_other_practise.txt'. Run
Code:
sudo find / -name links_to_*
again and it should give an error under normal circumstances because now it will expand to 'links_to_practise.txt' and 'links_to_other_practise.txt' before it is passed to find.

See also my EDIT in my previous post.
 
2 members found this post helpful.
Old 01-05-2011, 08:53 AM   #13
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Ok I just tried what you said
Quote:
find: paths must precede expression: links_to_practise.txt
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
Is this the error which you pointed?
 
Old 01-05-2011, 09:01 AM   #14
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Yes, your 'find' behaves as expected. This also means that the noglob flag is not set. Which should be the default. Now 'cd' into a directory that does NOT contain any file that starts with 'links_to_' and 'find' will succeed. As I explained earlier, if bash does not succeed to match and expand the wildcard it will pass 'link_to_*' to 'find'; with the asterisk! Then find's globbing mechanism will be able to treat the asterisk as wildcard in every directory it searches. You need to realize that there are in fact two globbing mechanisms involved here.
'Bash' and 'find'; both are capable of globbing.
 
2 members found this post helpful.
Old 01-05-2011, 09:09 AM   #15
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Awesome.This is great information I just tried what you said,in fact its one of its kind I had used it before but I did not knew this what you just said it did not gave any error this time.Even though I have used find many times but what you just told is simply awesome.
 
  


Reply



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
strange behavior of find tkmsr Debian 8 05-12-2010 08:31 AM
strange behavior of find or grep alenD Programming 4 09-21-2007 06:35 AM
Very Strange Behavior raysr Mandriva 4 08-31-2004 02:06 PM
Strange Behavior andrewb758 Linux - Hardware 5 08-31-2003 02:42 PM
strange behavior abhijit Linux - General 3 07-09-2003 11:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:55 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
Open Source Consulting | Domain Registration