How do I use the locate command within a specified directory?
来源:互联网 发布:java中的接口的作用 编辑:程序博客网 时间:2024/05/16 09:52
From: http://serverfault.com/questions/313733/how-do-i-use-the-locate-command-within-a-specified-directory
I am using the locate
command on Linux. My current usage of it searches through the entire filesystem. I only want it to search within a specific directory. How can I do this?
3 Answers
Another approach would be to use the pattern matching in locate
:
locate '/some/directory/*filename*'
Compare the output of the commands below:
$ locate tmpfile/usr/lib64/perl5/auto/POSIX/tmpfile.al/usr/share/man/fr/man3/tmpfile.3.gz/usr/share/man/ja/man3/tmpfile.3.gz/usr/share/man/man3/tmpfile.3.gz/usr/share/man/man3p/tmpfile.3p.gz$$ locate '/usr/lib64/*tmpfile*'/usr/lib64/perl5/auto/POSIX/tmpfile.al$
locate /usr/lib*tmpfile*
gives the same result.
The simplest answer I can think of is
locate search_term | grep "/specified/directory"
The better solution might be to use "find" and its path options...
Create slocate database for your specific directory with:
locate -U /path/to/directory
and search with:
locate <search_string>
UPDATE
This works fine on my Gentoo system but CentOS doesn't include -U
option. So, you can try below instead:
Build the database with:
# updatedb -U /path/to/dir -o dir_locate.db
and search:
# locate -d dir_locate.db <search_string>
- How do I use the locate command within a specified directory?
- How do I install a Package Manager within Cygwin ?
- How do I import a new Java CA cert without using the keytool command line utility?
- How to use 'cp' command to exclude a specific directory?
- How do I get the “Command Buffer” in Solaris 10?
- How do I get a MAC address via command line?
- How do I use software from a PPA?
- What is a cronjob and how do I use it?
- How do I use IStream?
- When I use the Report Viewer ,I have the error,how should i do?
- How do I pass data between Activities/Services within a single application?
- How do I grab an INI value within a Linux shell script?
- How do I grab an INI value within a shell script?
- How do I make my GUI plot into an axes within the GUI figure rather than inside of a new figure in M
- How do I find the PublicKeyToken for a particular dll?
- How do I hide a menu item in the actionbar?
- How can I determine the byte offset of a field within a structure?
- How do I use Cygwin in Geophysics ?
- excel转pdf转换器在线
- VxWorks引导启动过程
- 51单片机中的周期
- 自控和仿真软件开源好不好?
- 组合(Lucas)
- How do I use the locate command within a specified directory?
- [C#] VS2012连接SQL Server2012数据库的连接方式
- HDU1022--火车进出站问题Ⅰ
- C#元祖Tuple的事例
- B - Ugly Numbers(1.5.8)
- POJ 1946 Cow Cycling DP
- 字符串的基本知识点
- 题目一
- 滚动数组的应用
$ locate '/usr/lib64/*tmpfile'
will return no results. – xofer Sep 21 '11 at 4:36