Help - Search - Members - Calendar
Full Version: Howto List Path & Filename?
Linuxhelp > Support > Technical Support
ubivis
I need a shell command that will list the full path
and filename of a file.

For example:
If readme.txt was in /home/guy

I need a command like:
ls --fullpath

that would output:
/home/guy/readme.txt

Anyone know how?
ubivis
Just figured out the answer to my own question.
If you want to find the path of all files ending with jpg
from your current working directory:

find ./ -name *.jpg
hughesjr
To make this more compatable with more Linux, BSD and UNIX installs, I would recommend to do it like this:

find . -name '*.jpg'

Notes:
1. You can use ./ but . works as well and is one less key stroke.
2. Using single quotes is required for sh and csh using HP-UX 9, 10, and 11 ... and it works in FreeBSD and all versions of UNIX and Linux I have tried.
---------------------------------
find is very slow ... if you keep your slocate database updated then slocate can do searches in a couple seconds that take find several minutes... (on my servers I run a cron that updates the slocate database hourly and takes about 15 seconds).

This is the code to update the slocate database:

CODE
#!/bin/sh
renice +19 -p $$ >/dev/null 2>&1
/usr/bin/updatedb -f "nfs,smbfs,ncpfs,proc,devpts" -e "/tmp,/var/tmp,/usr/tmp,/afs,/net"


If you name it slocate.cron and stick it in the directory named /etc/cron.hourly (by default it is in /etc/cron.daily on redhat systems, so just move it to /etc/cron.hourly), it will update your files hourly. (don't forget to do chmod 755 slocate.cron)

You can't use a relative path (like . .. or ./) but you can use a full path ... so if you want a list of all the .jpg files under /usr/local the the command would be:

slocate /usr/local/*.jpg

and on my pc the results are:

CODE
/usr/local/j2sdk1.4.2/jre/javaws/resources/miniSplash.jpg
/usr/local/j2sdk1.4.2/jre/javaws/resources/copyright.jpg
/usr/local/j2sdk1.4.2/jre/javaws/resources/splash.jpg
/usr/local/j2sdk1.4.2/demo/jfc/FileChooserDemo/images/jpgIcon.jpg
/usr/local/j2sdk1.4.2/demo/plugin/jfc/FileChooserDemo/images/jpgIcon.jpg

-------------------------------
again ... slocate only contains the files that are in the database ... so the more frequently you update it ... the more accurate the searches are.

I also have a script that updates the database in /usr/bin called slocate_update (actually, it is just a logical link to /etc/cron.hourly/slocate.cron). I can then do the command slocate_update (either at the command line or called from inside a search script), then do the slocate command if I want a search that is up to the minute....even with the overhead of updating the databse, the search is still usually faster than find, especially on multiple directories.

To create a link from /usr/bin (named slocate_update) that points to the file /etc/cron.hourly/slocate.cron, use this command:

ln -s /etc/cron.hourly/slocate.cron /usr/bin/slocate_update
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.