LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 11:22 AM   #1
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

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, 11:41 AM   #2
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
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, 11:51 AM   #3
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

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, 11:53 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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, 11:58 AM   #5
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,594
Blog Entries: 19

Rep: Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455
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-27-2016, 11:45 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 12:33 AM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,130

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

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
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, 05:28 PM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,130

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
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, 01:35 AM   #10
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
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, 07:08 AM   #11
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

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

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

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
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, 09:40 AM   #14
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
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, 10:04 AM   #15
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,650

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
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



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 06:33 PM
Need help to find out some commands kasparov29 Linux - General 4 10-01-2011 05:29 PM
What's the difference between these two find commands? cola Programming 10 01-08-2010 02:04 PM
Where to find commands? spotterke Linux - Newbie 4 09-11-2008 04:34 PM
find commands shawniecas Linux - Newbie 4 06-14-2007 11:25 AM

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

All times are GMT -5. The time now is 08:16 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