Thursday, April 22, 2010

How to search file in Linux using a locate command

The idea of locate command is straightforward.

If a search pattern does not contain any metacharacters, locate command displays all file names that contain that string at any position of the path:

$> locate yastbrowser
/usr/share/YaST2/yastbrowser
/usr/share/YaST2/yastbrowser/application.ini
/usr/share/YaST2/yastbrowser/chrome
/usr/share/YaST2/yastbrowser/chrome/chrome.manifest
/usr/share/YaST2/yastbrowser/chrome/classic-browser.jar
/usr/share/YaST2/yastbrowser/chrome/en-US.jar
/usr/share/YaST2/yastbrowser/chrome/yastbrowser.jar
/usr/share/YaST2/yastbrowser/components
/usr/share/YaST2/yastbrowser/components/nsCmdlineHandler.js
/usr/share/YaST2/yastbrowser/defaults
/usr/share/YaST2/yastbrowser/defaults/preferences
/usr/share/YaST2/yastbrowser/defaults/preferences/yastbrowser-prefs.js


If pattern does contain metacharacters, locate shows only matching pathes:

$> locate *yastbrowser
/usr/share/YaST2/yastbrowser

No comments:

Post a Comment