Sunday, September 11, 2011

Locate command with examples


The locate command can quickly find a file.
When invoked, locate does not trail tree your disc, but uses a database to retrieve the file faster.
Advantage :
Search very rapidly.
Disadvantage :
It searches the files which are only in database or it won’t locate the file
To solve this problem. The command updatedb will update the database.
The generic syntax of locate is simple:
locate xyzfile
Without option, locate will return all occurrences of  xyzfile.
Some options to refine your search ,Search all files .py  and does not display error messages.
locate “*.py” -q
result
/usr/src/linux-headers-2.6.32-21/scripts/rt-tester/rt-tester.py
/usr/src/linux-headers-2.6.32-21/scripts/tracing/draw_functrace.py
/usr/src/linux-headers-2.6.32-22/scripts/rt-tester/rt-tester.py
/usr/src/linux-headers-2.6.32-22/scripts/tracing/draw_functrace.py
/usr/src/linux-headers-2.6.32-23/scripts/rt-tester/rt-tester.py
/usr/src/linux-headers-2.6.32-23/scripts/tracing/draw_functrace.py
/usr/src/linux-headers-2.6.32-24/scripts/rt-tester/rt-tester.py
/usr/src/linux-headers-2.6.32-24/scripts/tracing/draw_functrace.py
/usr/src/linux-headers-2.6.32-25/scripts/rt-tester/rt-tester.py
/usr/src/linux-headers-2.6.32-25/scripts/tracing/draw_functrace.py
/usr/src/linux-headers-2.6.32-26/scripts/rt-tester/rt-tester.py
/usr/src/linux-headers-2.6.32-26/scripts/tracing/draw_functrace.py
Search  for xorg file and limits the number of entries to 10
locate “xorg” -n 10
/xorg.conf.new
/etc/X11/xorg.conf
/etc/X11/xorg.conf-backup-100508180533
/etc/X11/xorg.conf.backup
/etc/X11/xorg.conf.failsafe
/etc/alternatives/xorg_extra_modules
/lib/udev/rules.d/40-xserver-xorg-video-intel.rules
/lib/udev/rules.d/64-xorg-xkb.rules
/lib/udev/rules.d/66-xorg-synaptics.rules
/lib/udev/rules.d/69-xorg-vmmouse.rules
Search for in case sensitive file name
locate -i XYZ.PHP