bug-coreutils
[Top][All Lists]
Advanced

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

ls: add a switch not to strip the directory we gave


From: Dan Jacobson
Subject: ls: add a switch not to strip the directory we gave
Date: Tue, 13 May 2003 09:54:27 +0800
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i386-pc-linux-gnu)

The following message is a courtesy copy of an article
that has been posted to comp.unix.shell as well.

M> so it is *still* not clear what you're looking for. The suggesting
M> from Jim Meyering to use find does sound like the best way to get
M> whatever it is you want, since you can customize the output.

Currently if one wants the _full path_ of the latest file
of a directory other than the current one, then
f=`ls -t ~/.procmail/bitbucket|sed q`
will not do.
One must do f=`ls -t ~/.procmail/bitbucket/*|sed q`
which is a big waste in the shell and might even exceed some
argument limits. Or, one must dance around:
a=~/.procmail/bitbucket/
x=`ls -t $a|sed q`
f=$a/$x
all because ls has no switch to make it output the directory it was
given.

Jim> How about using find instead?

Jim>   find /tmp -printf '%T@ %TY-%Tm-%Td ... %p\n' | sort -nr

my goodness, that is pulling out all the stops...
Hmm,
f=`find ~/.procmail/bitbucket -type f -printf '%T@ %p\n'|
 sort -nr|awk '{print $2;exit}'`
was as efficient as I could make Jim's solution.

Anyways what I want to do is
f=`ls -t --dont-strip-path-I-was-given ~/.procmail/bitbucket|sed q`
i.e. getting the full path of the latest file there, just using ls and
sed, without the above "more involved" workarounds.

Anyways, I hope I have show the "reasonable case" for adding one more
option to the venerable ls command.
-- 
http://jidanni.org/ Taiwan(04)25854780




reply via email to

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