Unix C++
Would you like to react to this message? Create an account in a few clicks or log in to continue.

exact file search?

+2
Christopher
Naveen
6 posters

Page 1 of 2 1, 2  Next

Go down

exact file search? Empty exact file search?

Post by Naveen Mon Mar 08, 2010 4:40 pm

givin the command
"$ locate nav" gives all the combination of files/directory with name nav, i wan the exact search of file named nav.
is there ne command?

Naveen

Posts : 15
Points : 21
Join date : 2010-03-05
Age : 35

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Christopher Mon Mar 08, 2010 5:42 pm

locate ll search for the file in the entire file system. so if more than one file contains the query string in filename, all will be displayed. If u want to be more specific, give valid extensions to ur file.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Naveen Mon Mar 08, 2010 5:46 pm

Without extension is it possible?

Naveen

Posts : 15
Points : 21
Join date : 2010-03-05
Age : 35

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Maithreyi Mon Mar 08, 2010 6:14 pm

If you wanna use locate to find files with nav then you can pipe the output of locate to grep.Using $ will give you files ending with nav.This can narrow it down atleast although it is not the right command for your problem.

for eg : locate * | grep "nav$"

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Naveen Mon Mar 08, 2010 6:28 pm

@above
I got ur point..
Thanx..
Do lemme know if u cum to know how to find the exact search?

Naveen

Posts : 15
Points : 21
Join date : 2010-03-05
Age : 35

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Christopher Mon Mar 08, 2010 7:01 pm

sure..
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

exact file search? Empty Re: exact file search?

Post by akalya Mon Mar 08, 2010 7:25 pm

guess this works

locate * | grep -w "nav"

w considers the pattern given as a word preceded or followed only by non-word constituent characters..word constituent characters is letters,digits,underscore


Last edited by akalya on Mon Mar 08, 2010 7:28 pm; edited 1 time in total

akalya

Posts : 70
Points : 86
Join date : 2010-03-04

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Maithreyi Mon Mar 08, 2010 7:26 pm

suppose you have two files naveen and nav under your directory -

then ls * | grep nav will give you naveen and nav
but, ls * | grep -x nav will give you only nav

grep -x finds the exact match of the pattern.However, with locate this does not show anyoutput because there is no file with just nav!

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Saradha Kannan Tue Mar 09, 2010 1:03 pm

@ mait : hey cud u pls explain wy it doesnt work with locate even when der s a file "nav"?

Saradha Kannan

Posts : 25
Points : 25
Join date : 2010-03-04

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Christopher Tue Mar 09, 2010 1:05 pm

@akalya
it wont work. consider there are two files named 'abc' and 'abc.txt'. Both will be displayed. when u r searching for a file, all files which contains the query string ll be displayed. i think it is not possible to search for a particular file named "nav".

@maithreyi
u can search for a particular file if u r using ls. it ll search only in the current directory. But he wants to search in the entire file system(locate).
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Maithreyi Wed Mar 10, 2010 11:20 am

@ sarada - locate searches the entire file system.
Try locate -r nav
It will return all matches having the pattern nav in the path.
There is no file called nav in the search.
nav will only form a part of the path.
But,for exact search use grep -x.
So suppose you want to retrieve a particular file or path, give
locate * | grep -x "the full path of the file you are looking for"

eg : - locate * | grep -x /usr/share/icons/hicolor/32x32/stock/navigation

Will give you the file with this exact path.
-x will find the file with the exact matched string
If you had given locate *|grep -x nav, then if there was nav in the filesystem directly it would have been found!

Hope it helps!

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Maithreyi Wed Mar 10, 2010 11:23 am

As Christopher said only filename will not help with locate!

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Christopher Wed Mar 10, 2010 11:39 pm

to search for a file exactly named 'nav', use following command.

Code:
$ locate -b '\nav'

It ll return only files exactly named 'nav'.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

exact file search? Empty Re: exact file search?

Post by akalya Thu Mar 11, 2010 12:43 pm

@christopher
could u please explain as to wat it(locate -b) means???

akalya

Posts : 70
Points : 86
Join date : 2010-03-04

Back to top Go down

exact file search? Empty Re: exact file search?

Post by jeeva Thu Mar 11, 2010 12:56 pm

akalya... -b means basename.... see using man cmd itself na

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Christopher Thu Mar 11, 2010 1:21 pm

but still the result is not just beacuse of -b, '\' is the main reason. there s a special name for that character. i found it in ubuntu 9.10 shell's manual. but i forgot scratch
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

exact file search? Empty Re: exact file search?

Post by akalya Thu Mar 11, 2010 1:31 pm

@jeeva
i tried man.....but it din give me the reason for using '\' !!!!! and the command is not working without using '\' !!!

akalya

Posts : 70
Points : 86
Join date : 2010-03-04

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Christopher Thu Mar 11, 2010 1:57 pm

default locate behaviour is --wholename(-w). which means it ll return all the files which may not contain 'nav' in filename(but it contains 'nav' in complete path).

But if u use --basename(-b), the filename should contain 'nav'. if u put '\' before query string, it is returning files exactly named 'nav'.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

exact file search? Empty Re: exact file search?

Post by jeeva Thu Mar 11, 2010 2:05 pm

i have another doubt
does find 'filename' makes an exact file search too??

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

Back to top Go down

exact file search? Empty Re: exact file search?

Post by akalya Thu Mar 11, 2010 2:09 pm

but find 'filename' doesn give u the entire path info......

akalya

Posts : 70
Points : 86
Join date : 2010-03-04

Back to top Go down

exact file search? Empty Re: exact file search?

Post by jeeva Thu Mar 11, 2010 2:12 pm

ya thats right... ok

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Christopher Thu Mar 11, 2010 2:55 pm

'find' is used to search in a particular directory. 'locate' is used to search the entire file system. there is a huge difference.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

exact file search? Empty Re: exact file search?

Post by jeeva Thu Mar 11, 2010 3:59 pm

find can also be used to search in a directory and its sub directories too...

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Christopher Thu Mar 11, 2010 4:04 pm

still only inside directory and its sub directories not the entire file system.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Christopher Thu Mar 11, 2010 4:09 pm

btw how to search in sub directories using 'find'.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

exact file search? Empty Re: exact file search?

Post by Sponsored content


Sponsored content


Back to top Go down

Page 1 of 2 1, 2  Next

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum