LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 10-26-2016, 12:22 PM   #1
robertkwild
Member
 
Registered: Feb 2015
Posts: 376

Rep: Reputation: Disabled
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
 
Old 10-26-2016, 12:41 PM   #2
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 579

Rep: Reputation: 275Reputation: 275Reputation: 275
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.
...
 
Old 10-26-2016, 12:51 PM   #3
robertkwild
Member
 
Registered: Feb 2015
Posts: 376

Original Poster
Rep: Reputation: Disabled
what about if the filename/folder is named something else but it has got spiceworks in the name of the file/folder?
 
Old 10-26-2016, 12:53 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,242

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
Quote:
Originally Posted by robertkwild View Post
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*"
 
Old 10-26-2016, 12:58 PM   #5
hazel
Senior Member
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 2,681
Blog Entries: 6

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
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.
 
Old 10-28-2016, 12:45 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,602

Rep: Reputation: 2445Reputation: 2445Reputation: 2445Reputation: 2445Reputation: 2445Reputation: 2445Reputation: 2445Reputation: 2445Reputation: 2445Reputation: 2445Reputation: 2445
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 ...
 
Old 10-28-2016, 01:33 AM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 17,518

Rep: Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744
Better to use "locate" if appropriate - especially if lots of queries are likely.
 
Old 10-28-2016, 01:05 PM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 10,759
Blog Entries: 7

Rep: Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694
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.
 
Old 10-28-2016, 06:28 PM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 17,518

Rep: Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744Reputation: 2744
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.
 
Old 10-31-2016, 02:35 AM   #10
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 10,759
Blog Entries: 7

Rep: Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694Reputation: 2694
Quote:
Originally Posted by syg00 View Post
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!"
 
Old 10-31-2016, 08:08 AM   #11
robertkwild
Member
 
Registered: Feb 2015
Posts: 376

Original Poster
Rep: Reputation: Disabled
thanks guys
 
Old 10-31-2016, 10:20 AM   #12
robertkwild
Member
 
Registered: Feb 2015
Posts: 376

Original Poster
Rep: Reputation: Disabled
does the find command do recursive aswell
 
Old 10-31-2016, 10:34 AM   #13
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 21,064

Rep: Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275
Quote:
Originally Posted by robertkwild View Post
does the find command do recursive aswell
Yes, it does, if you tell it to.
 
Old 10-31-2016, 10:40 AM   #14
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Debian, Arch, FreeBSD & OpenBSD novice, Hackintosh
Posts: 1,177
Blog Entries: 7

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
Quote:
Originally Posted by TB0ne View Post
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.
 
Old 10-31-2016, 11:04 AM   #15
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 21,064

Rep: Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275Reputation: 5275
Quote:
Originally Posted by goumba View Post
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??"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question using cp and find commands. thornt Linux - Newbie 1 02-10-2015 07:33 PM
Need help to find out some commands kasparov29 Linux - General 4 10-01-2011 06:29 PM
What's the difference between these two find commands? cola Programming 10 01-08-2010 03:04 PM
Where to find commands? spotterke Linux - Newbie 4 09-11-2008 05:34 PM
find commands shawniecas Linux - Newbie 4 06-14-2007 12:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 09:07 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration