LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Question on Find Command: - Vs + (https://www.linuxquestions.org/questions/linux-newbie-8/question-on-find-command-vs-722374/)

JockVSJock 04-28-2009 08:53 PM

Question on Find Command: - Vs +
 
Been using Linux for sometime and realized that you have the following option:

find / -name foo.txt (this allows a person to find all of the files)

Vs

find / +name foo.txt (this allows a person to find any of the files)


My sticking point is what is the difference between all Vs any?

thanks

Tinkster 04-28-2009 09:29 PM

Hmmm ... I'm curious: where did you stumble across this?
While it seems to work (albeit with - let's say - unexpected
results), I can't seem to find this invocation referenced in
finds documentation?


Cheers,
Tink

billymayday 04-28-2009 09:44 PM

Output of ls in test directory

Code:

ls
test1  test2

output of find ./ -name test1

Code:

find ./ -name test1
./test1

output of find ./ +name test1
Code:

find ./ +name test1
./
./test1
./test2
find: +name: No such file or directory
test1

output of find ./
Code:

find ./
./
./test1
./test2

In short, I think all you are doing is generating an error that results in find invocating three times.

Are you seeing different results?

JockVSJock 04-28-2009 09:46 PM

Ok, my goof.

I'm studying for my Linux+, and I'm using the following book:

Linux+ Study Guide, 3rd Edition by Roderick W Smith.

I found this in chp 2 and didn't see that you need to also use, -perm.

I then checked the man page for find and now it makes sense:

Code:

-perm mode
     
File’s  permission  bits are exactly mode (octal or symbolic).  Since an exact match is required, if you want
to use this form for symbolic modes, you may have to specify a rather complex mode string.  For example -perm
g=w  will  only  match files which have mode 0020 (that is, ones for which group write permission is the only
permission set).  It is more likely that you will want to use the ‘/’ or ‘-’ forms, for example  -perm  -g=w,
which matches any file with group write permission.  See the EXAMPLES section for some illustrative examples.


Code:

-perm +mode
             
Deprecated, old way of searching for files with any of the permission bits in mode set.  You should use -perm
/mode instead. Trying to use the ‘+’ syntax with symbolic modes will yield surprising results.  For  example,
‘+u+x’ is a valid symbolic mode (equivalent to +u,+x, i.e. 0111) and will therefore not be evaluated as -perm
+mode but instead as the exact mode specifier -perm mode and so it matches files with exact permissions  0111
instead  of  files  with any execute bit set.  If you found this paragraph confusing, you’re not alone - just
use -perm /mode.  This form of the -perm test is deprecated because  the  POSIX  specification  requires  the
interpretation of a leading ‘+’ as being part of a symbolic mode, and so we switched to using ‘/’ instead.


-perm +mode is the old way of search for any of the permission bits in
mode set.

thanks

chrism01 04-29-2009 01:44 AM

'-' and '+' also apply to timestamps (ctime, mtime, atime) in find cmd. See man page.


All times are GMT -5. The time now is 09:53 PM.