bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: find printing full paths


From: The Wanderer
Subject: Re: find printing full paths
Date: Thu, 15 Jun 2006 13:44:42 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922

Bob Proulx wrote:

The Wanderer wrote:

For the little it's worth, I also find myself wanting to do
something like this from time to time, usually in a context in
which find is not a satisfactory alternative - or, at best, in
which it would be awkward and potentially difficult to construct a
find command which would match all of the desired files and no
others.

Could you give an example?  The find command has a rich feature set
and I am having a hard time imagining a case such as you describe.

Mostly I just notice them as I run across them, then forget them until
next time. Since writing that post, I've done a little experimentation,
and discovered both a complicated way and a simple way to accomplish
with find the single example I was able to remember - which I now think
I may have misremembered, because the simple way is comparatively
obvious (assuming you know about '-mindepth' and '-maxdepth', which I
keep mixing up with e.g. du's '--max-depth'/'--max' syntax).


What I was doing at the time, so far as I remember, was:

for i in `ls path/to/directory1/ path/to/directory2/` ; do ls -l $i && <complex operation I don't care to reproduce here> $i ; done

but that didn't work because the filename printed by the subshell did
not exist in the present directory. I've since figured out that I could
do something of the same thing with either

==
find path/to/directory1/ path/to/directory2/ -mindepth 1 -maxdepth 1 -exec ls -l {} \; -exec <complex operation> {} \;
==

(the "complicated way" I referred to, which hadn't occurred to me at the
time both because the '-mindepth' and '-maxdepth' options are
irritatingly verbose enough to be bothersome to use and because it
hadn't occurred to me to consider the possibility of multiple '-exec'
options) or

==
for i in `find path/to/directory1/ path/to/directory2/ -mindepth 1 -maxdepth 1` ; do ls -l $i && <complex operation> $i ; done
==

(the "simple way").

Regardless, even though it can accomplish the task, I do not necessarily
consider the above command to be "satisfactory"; the reasons were
clearer to me when I wrote the previous post than they are now, but I
believe they boil down to "sufficiently complicated to require at least
a moment of concentration to work out, which would distract me from the
task at hand".

(For that matter, I've just scoured the man page to find, and I do
not see an option to make it print the absolute path to the file
rather than the path relative to the directory from which find was
invoked.)

Does this work for you?

find $PWD

If I were attempting to find in the hierarchy beginning at the curent
directory, that would be fine. However, it is far more common for me to
want to find in some hierarchy other than the one I'm currently at the
top of, and/or more than one hierarchy at once (say, two or three
directories out of a dozen or more in the current directory, or one
directory under the current one and one in some other arbitrary location
- yes, this has happened), in which case I don't believe that would have
the desired result.

--
      The Wanderer gripes once again about the Reply-To aggravation

Warning: Simply because I argue an issue does not mean I agree with any
side of it.

Secrecy is the beginning of tyranny.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]