How do I search for a file where I know the name but not the location?

0

i want to search qdbase (the name of DB). i dont know where this file is lies.i want to use grep at my server. my server name is qa@qaubuntu and for root root@qaubuntu.. i'm searching this file using terminal from client PC(qa@qadesktop)

klox

Posted 2010-07-20T04:38:11.967

Reputation: 521

Answers

2

So you're looking for a file with a known name and unknown location?

Two options:

  1. locate qdbase
  2. sudo find / -name qdbase -print

The latter is probably slower, but more "thorough", the first command is based on the fact that all file names have been indexed already, so that the search is quicker. Try the first option and if it fails, the second one.

You'll probably have to rsh in first. grep is used to find data inside a file, so it's probably not what you want here. The sudo part is needed for permission reasons.

Henno

Posted 2010-07-20T04:38:11.967

Reputation: 639

0

sudo grep / "String to search for"

sudo to not restrict the search by what folders your regular user is allowed access to

grep to search

/ for the root of the drive

"String to search for"

EricR

Posted 2010-07-20T04:38:11.967

Reputation: 453

"qa@qaubuntu:~$ sudo grep /qdbase" like this? – klox – 2010-07-20T04:45:25.397

sudo grep / "qdbase" – EricR – 2010-07-20T04:53:41.493

this grep command does not work: it's grep [options] regexp file [file] where regexp is a regular expression, which can be a string, but can need escaped characters etc. So it's not quite that simple. – Henno – 2010-07-20T04:54:33.690

that's for finding text in files, if you're looking for a name, I use cd / && find -iname "qdbase" – EricR – 2010-07-20T04:56:50.613

@Henno, It will search for string as long as you don't through in any characters that don't need to be escaped. In my experience, grep doesn't play nearly as well with the regex strings that I've used as egrep. – EricR – 2010-07-20T04:57:51.047

2the fact remains that you give / as a first argument (which is the string to search) and a location (file, or directory if you use the -r option), the second argument, named "string to search for". So the order is wrong. If you do sudo grep -r -l 'string to search for' / (which will take a very long time, presumably) you will get a list of all files that contain that string... – Henno – 2010-07-20T05:02:58.413

Fair enough, my mistake. – EricR – 2010-07-20T05:09:15.917