LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   CentOS (https://www.linuxquestions.org/questions/centos-111/)
-   -   different find commands to use (https://www.linuxquestions.org/questions/centos-111/different-find-commands-to-use-4175592277/)

robertkwild 10-26-2016 11:22 AM

different find commands to use
 
hi all,

im taking charge of all the companys archive/restore jobs for data backups on LTO tapes and sometimes people dont know the location of the file(s)/folder(s)

i know you can use the find command for this but i want to know a few commands to find certain keywords, like if the file or folder has any words or letters like "spiceworks"

many thanks,

rob

Sefyir 10-26-2016 11:41 AM

There are a lot of different kinds of ways to use find
The find man page is a excellent resource

Code:

man find
Code:

NAME
      find - search for files in a directory hierarchy

SYNOPSIS
      find  [-H]  [-L]  [-P]  [-D  debugopts]  [-Olevel]  [starting-point...]
      [expression]

DESCRIPTION
      This manual page documents the GNU version of find.  GNU find  searches
      the  directory  tree  rooted at each given starting-point by evaluating
      the given expression from left to right,  according  to  the  rules  of
      precedence  (see  section  OPERATORS),  until the outcome is known (the
      left hand side is false for and operations,  true  for  or),  at  which
      point  find  moves  on  to the next file name.  If no starting-point is
      specified, `.' is assumed.

      If you are using find in an environment  where  security  is  important
      (for  example  if  you  are  using  it  to  search directories that are
      writable by other users), you should read the "Security Considerations"
      chapter  of  the findutils documentation, which is called Finding Files
      and comes with findutils.  That document  also  includes  a  lot  more
      detail  and discussion than this manual page, so you may find it a more
      useful source of information.
...


robertkwild 10-26-2016 11:51 AM

what about if the filename/folder is named something else but it has got spiceworks in the name of the file/folder?

schneidz 10-26-2016 11:53 AM

Quote:

Originally Posted by robertkwild (Post 5623244)
what about if the filename/folder is named something else but it has got spiceworks in the name of the file/folder?

a freebie:
Code:

find . -name "*spiceworks*"

hazel 10-26-2016 11:58 AM

If the string you want is part of the filename, you can use wildcards with find, providing you enclose the string in quotes. Or you can use locate, which automatically picks up substrings unless you tell it not to.

To find a file with a particular string in the text, use find and pipe the result through xargs grep. For example
Code:

find somedirectory -name "*"|xargs grep somestring
This will search all files that come under somedirectory (* is a total wildcard) and check the contents of each one for the string somestring.

chrism01 10-27-2016 11:45 PM

I'll just recommend using single quotes instead of double there. This ensures the wildcard pattern is interpolated by the find cmd, rather than the shell - this makes a difference ...

syg00 10-28-2016 12:33 AM

Better to use "locate" if appropriate - especially if lots of queries are likely.

ondoho 10-28-2016 12:05 PM

i don't like locate.
i always have the feeling it wants me to believe that it's making a realtime search, but in reality it only accesses a database that was created... when? last time updatedb ran?

and when updatedb runs, it takes lots of resources, usually at a time when i don't have the patience for it.

no, better use find, and learn to use it properly.

or consult packet management about installed files.

syg00 10-28-2016 05:28 PM

An environment with multiple users and using LTO tapes ain't your typical home user. They are probably running updatedb in the wee hours every night. So yes the database may be "out of date" for todays files. Easy (and cheap resource-wise) to rectify.
"find" works as we all know, but locate has it's place. I find I have to rerun the updatedb about once a week - takes little time these days.

ondoho 10-31-2016 01:35 AM

Quote:

Originally Posted by syg00 (Post 5624289)
using LTO tapes

i forgot about that bit.

ok, i guess my previous post was opinionated.
but it stands, esp. because i've seen (more than once) forum posts like: "why don't you use locate? it's much faster than find!"
:doh:

robertkwild 10-31-2016 07:08 AM

thanks guys

robertkwild 10-31-2016 09:20 AM

does the find command do recursive aswell

TB0ne 10-31-2016 09:34 AM

Quote:

Originally Posted by robertkwild (Post 5625162)
does the find command do recursive aswell

Yes, it does, if you tell it to.

goumba 10-31-2016 09:40 AM

Quote:

Originally Posted by TB0ne (Post 5625174)
Yes, it does, if you tell it to.

Actually it is recursive unless you tell it not to be so (-maxdepth 1). For the OP: this also means you can limit the depth of recursion.

TB0ne 10-31-2016 10:04 AM

Quote:

Originally Posted by goumba (Post 5625178)
Actually it is recursive unless you tell it not to be so (-maxdepth 1). For the OP: this also means you can limit the depth of recursion.

Good point, and you're exactly right.

To the OP, though, related to your original post...what are you using currently to take your backups? It could be that the software itself maintains a database as to what's written, that you could query via SQL (like Tivoli Storage Manager, for example), and see file names/locations.

And it always has entertained me over the years that end-users can't tell you where the file is, or what it's called...but somehow 'know' they need it restored. The follow-up questions are similarly entertaining..."Well, since you don't know what drive you saved it to, what the file name is...what program did you use to create it?", "I used MICROSOFT...that's all I know", ".......".

I asked someone one time "Since you don't know where it was, or what it was named, then how do you know it's missing??" :)


All times are GMT -5. The time now is 03:18 AM.