home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] Odd behaviour in find

On 11/25/2015 02:21 PM, Alex Pilon wrote:
>> On 15-11-25 01:39 PM, Alex Pilon wrote:
>>> Is it just me or should this work?

It's just you who skipped reading the man page
  find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
note that we have some options before "path" and expressions after. That
means that "foo" below is a path, not file/directory to search for.
To just search for a file/directory you can use "locate foo" (assuming
it's installed and the cronjob to update the db is running)

>>>
>>>     $ find -xdev -- foo
>>>     find: unknown predicate `--'
"find" - command
"-xdev" - Don’t descend directories on other filesystems.
"--" - "A double dash -- can also be used to signal that any remaining
arguments are not options"
"foo" directory to search in


>>>     $
>>>
>>> But not this?
>>>
>>>     $ find -- foo -xdev -name 'sadasdasdasd'
"find" - command
"--" - "A double dash -- can also be used to signal that any remaining
arguments are not options"
"foo" directory to search in
"-xdev" - Don’t descend directories on other filesystems.
"-name 'sadasdasdasd'" - search for an object named sadasdasdasd

> 
>     $ find -- sadasdasdasd
>     find: `sadasdasdasd': No such file or directory

"find" - command
"--" - remaining arguments aren't options
"sadasdasdasd" - directory to search in and assuming you don't have a
directory named "sadasdasdasd" it's all expected


So if you want to search for sadasdasdasd  you need to run
   find -name sadasdasdasd
to search for it in current (".") directory.
To find files  over 10M in /var you can
   find /var -size +10M -ls
To find logfiles older than 365 days you can
   find /var/log -type f -name "*.log" -mtime +365 -ls

And so on, "man find" for more about it.


/ps