exact file search?
+2
Christopher
Naveen
6 posters
Page 1 of 2 • 1, 2
exact file search?
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?
"$ 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
Re: exact file search?
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.
Re: exact file search?
Without extension is it possible?
Naveen- Posts : 15
Points : 21
Join date : 2010-03-05
Age : 35
Re: exact file search?
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$"
for eg : locate * | grep "nav$"
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Re: exact file search?
@above
I got ur point..
Thanx..
Do lemme know if u cum to know how to find the exact search?
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
Re: exact file search?
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
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
Re: exact file search?
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!
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
Re: exact file search?
@ 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
Re: exact file search?
@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).
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).
Re: exact file search?
@ 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!
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
Re: exact file search?
As Christopher said only filename will not help with locate!
Maithreyi- Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia
Re: exact file search?
to search for a file exactly named 'nav', use following command.
It ll return only files exactly named 'nav'.
- Code:
$ locate -b '\nav'
It ll return only files exactly named 'nav'.
Re: exact file search?
@christopher
could u please explain as to wat it(locate -b) means???
could u please explain as to wat it(locate -b) means???
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Re: exact file search?
akalya... -b means basename.... see using man cmd itself na
jeeva- Posts : 50
Points : 93
Join date : 2010-03-04
Re: exact file search?
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
Re: exact file search?
@jeeva
i tried man.....but it din give me the reason for using '\' !!!!! and the command is not working without using '\' !!!
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
Re: exact file search?
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'.
But if u use --basename(-b), the filename should contain 'nav'. if u put '\' before query string, it is returning files exactly named 'nav'.
Re: exact file search?
i have another doubt
does find 'filename' makes an exact file search too??
does find 'filename' makes an exact file search too??
jeeva- Posts : 50
Points : 93
Join date : 2010-03-04
Re: exact file search?
but find 'filename' doesn give u the entire path info......
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Re: exact file search?
'find' is used to search in a particular directory. 'locate' is used to search the entire file system. there is a huge difference.
Re: exact file search?
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
Re: exact file search?
still only inside directory and its sub directories not the entire file system.
Page 1 of 2 • 1, 2
Similar topics
» read from a file
» Change Owner of a File
» deleting a particular line in a file
» header file is not getting recognised (in Eclipse/C++)
» copying file contents across directories
» Change Owner of a File
» deleting a particular line in a file
» header file is not getting recognised (in Eclipse/C++)
» copying file contents across directories
Permissions in this forum:
You cannot reply to topics in this forum