Lsof
From Liki
lsof is a *nix command for listing open files. An excellent tutorial to using it for all kinds of useful things is here.
For example, if you want to know where the locate command keeps it's database
locate a > /dev/null & sudo lsof -p `jobs -p %1`
First we need to have `locate' running for a while. `locate a > /dev/null' will list all files with `a' in their path (quite a few of them :p). We pipe all this output to /dev/null, since we don't care about it and use the ampersand to background the process. With locate running in the backround (as job 1), we can get it's process ID with `jobs -p %1`, and use that PID with `lsof' (sudoing to get priveledges), to list all of locates open files.
The output on my Ubuntu machine looks like
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME locate 27630 wking cwd DIR 8,1 12288 1818626 /home/wking locate 27630 wking rtd DIR 8,1 4096 2 / locate 27630 wking txt REG 8,1 31308 9241558 /usr/bin/slocate locate 27630 wking mem REG 8,1 38420 229462 /lib/tls/i686/cmov/libnss_files-2.6.1.so locate 27630 wking mem REG 8,1 34352 229466 /lib/tls/i686/cmov/libnss_nis-2.6.1.so locate 27630 wking mem REG 8,1 83712 229453 /lib/tls/i686/cmov/libnsl-2.6.1.so locate 27630 wking mem REG 8,1 30436 229458 /lib/tls/i686/cmov/libnss_compat-2.6.1.so locate 27630 wking mem REG 8,1 1339816 229403 /lib/tls/i686/cmov/libc-2.6.1.so locate 27630 wking mem REG 8,1 109148 229389 /lib/ld-2.6.1.so locate 27630 wking 0u CHR 136,0 2 /dev/pts/0 locate 27630 wking 1w CHR 1,3 9399 /dev/null locate 27630 wking 2u CHR 136,0 2 /dev/pts/0 locate 27630 wking 3r REG 8,1 9940978 5096068 /var/lib/slocate/slocate.db
So the database is /var/lib/slocate/slocate.db

