Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )

Advanced DNS Management
New ZoneEdit. New Managment.


Sign Up Now
Reply to this topicStart new topic
> Howto List Path & Filename?
post Jan 19 2004, 04:49 AM
Post #1

Whats this Lie-nix Thing?

Group: Members
Posts: 3
Joined: 19-January 04
Member No.: 2,173

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:

Anyone know how?
Go to the top of the page
+Quote Post
post Jan 19 2004, 04:54 AM
Post #2

Whats this Lie-nix Thing?

Group: Members
Posts: 3
Joined: 19-January 04
Member No.: 2,173

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
Go to the top of the page
+Quote Post
post Jan 21 2004, 06:42 AM
Post #3

Its GNU/

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151

To make this more compatable with more Linux, BSD and UNIX installs, I would recommend to do it like this:

find . -name '*.jpg'

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:

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:


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

Johnny Hughes
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


RSS Lo-Fi Version Time is now: 21st October 2017 - 11:00 AM