|
Home > Archive > Unix Shell > September 2007 > Make ls print path
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Make ls print path
|
|
| Salve Håkedal 2007-09-15, 7:16 pm |
| Sometimes I'd like to do something like:
$ less $(ls email/inbox/cur | tail -n 1)
but that fails, because ls prints only the "basename".
I can't find an option to make ls print the path!
--
Salve Håkedal
| |
| Janis Papanagnou 2007-09-15, 7:16 pm |
| Salve Håkedal wrote:
> Sometimes I'd like to do something like:
>
> $ less $(ls email/inbox/cur | tail -n 1)
>
> but that fails, because ls prints only the "basename".
> I can't find an option to make ls print the path!
>
Use ~+ as, for example, in...
ls -d ~+/bin/*
Janis
| |
| Chris F.A. Johnson 2007-09-15, 7:16 pm |
| On 2007-09-15, Salve Håkedal wrote:
> Sometimes I'd like to do something like:
>
> $ less $(ls email/inbox/cur | tail -n 1)
>
> but that fails, because ls prints only the "basename".
> I can't find an option to make ls print the path!
less "$(ls -d email/inbox/cur/* | tail -n 1)"
Or (saves two external commands):
set -- email/inbox/cur/*
shift $(( $# - 1 ))
less "$1"
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
| |
| Stephane CHAZELAS 2007-09-15, 7:16 pm |
| 2007-09-15, 16:51(-05), Salve Håkedal:
> Sometimes I'd like to do something like:
>
> $ less $(ls email/inbox/cur | tail -n 1)
>
> but that fails, because ls prints only the "basename".
> I can't find an option to make ls print the path!
With zsh:
less email/inbox/cur/*([-1])
--
Stéphane
| |
| Salve Håkedal 2007-09-16, 7:26 am |
| On 2007-09-15, Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
> On 2007-09-15, Salve Håkedal wrote:
>
> less "$(ls -d email/inbox/cur/* | tail -n 1)"
>
> Or (saves two external commands):
>
> set -- email/inbox/cur/*
> shift $(( $# - 1 ))
> less "$1"
>
Thank you. I had not understood that that could be used with the file
name (= "basename")! (That is not really clear form the man page, is
it?)
--
Salve Håkedal
| |
| Salve Håkedal 2007-09-16, 7:26 am |
| On 2007-09-15, Janis Papanagnou <Janis_Papanagnou@hotmail.com> wrote:
> Salve Håkedal wrote:
>
> Use ~+ as, for example, in...
>
> ls -d ~+/bin/*
>
Fine! Thank you.
--
Salve Håkedal
|
|
|
|
|