Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #175771 > unrolled thread

[Newbie] Can ls command format output my way?

Started byRichard Owlett <rowlett@cloud85.net>
First post2016-12-17 16:50 +0100
Last post2016-12-17 19:00 +0100
Articles 9 — 6 participants

Back to article view | Back to linux.debian.user


Contents

  [Newbie] Can ls command format output my way? Richard Owlett <rowlett@cloud85.net> - 2016-12-17 16:50 +0100
    Re: [Newbie] Can ls command format output my way? Lars Noodén <lars.nooden@gmail.com> - 2016-12-17 17:00 +0100
      Re: [Newbie] Can ls command format output my way? David Wright <deblis@lionunicorn.co.uk> - 2016-12-17 18:10 +0100
        Re: [Newbie] Can ls command format output my way? Richard Owlett <rowlett@cloud85.net> - 2016-12-18 16:50 +0100
          Re: [Newbie] Can ls command format output my way? emetib <chadbrabec@gmail.com> - 2016-12-18 19:10 +0100
    Re: [Newbie] Can ls command format output my way? The Wanderer <wanderer@fastmail.fm> - 2016-12-17 17:00 +0100
    Re: [Newbie] Can ls command format output my way? Kushal Kumaran <kushal@locationd.net> - 2016-12-17 17:10 +0100
    THANK YOU [Re: [Newbie] Can ls command format output my way?] Richard Owlett <rowlett@cloud85.net> - 2016-12-17 18:20 +0100
    Re: [Newbie] Can ls command format output my way? emetib <chadbrabec@gmail.com> - 2016-12-17 19:00 +0100

#175771 — [Newbie] Can ls command format output my way?

FromRichard Owlett <rowlett@cloud85.net>
Date2016-12-17 16:50 +0100
Subject[Newbie] Can ls command format output my way?
Message-ID<sPppg-31r-9@gated-at.bofh.it>
ls -R /media/data produces the content but not the NEEDED format.

I want a list like:
/media/data/dir1/filea
/media/data/dir1/fileb
/media/data/dir1/subdir1/filex
/media/data/dir1/subdir1/filey
/media/data/dir1/subdir1/filez
/media/data/dir2/filea
/media/data/dir2/fileb
/media/data/dir2/subdir1/filex
/media/data/dir2/subdir1/filey
/media/data/dir2/subdir1/filez
et cetera

I don't wish anything but full path to all files in a top level 
directory.

Followup question how should I found the answer for myself. I 
looks basic enough ...
TIA

[toc] | [next] | [standalone]


#175772

FromLars Noodén <lars.nooden@gmail.com>
Date2016-12-17 17:00 +0100
Message-ID<sPpyW-34V-11@gated-at.bofh.it>
In reply to#175771
On 12/17/2016 05:40 PM, Richard Owlett wrote:
[...]
> I don't wish anything but full path to all files in a top level directory.
> 
> Followup question how should I found the answer for myself. I looks
> basic enough ...
> TIA

One way would be to use find combined with realpath.

	find /media/data -exec realpath "{}" \;

That's recursive.  If you want only that one directory, limit how deep
it may go:

	find /media/data -maxdepth 1 -exec realpath "{}" \;

If that's too long to type out each time, you can make a shell alias or
function that accepts the path as an option and then passes that to find.

/Lars

[toc] | [prev] | [next] | [standalone]


#175775

FromDavid Wright <deblis@lionunicorn.co.uk>
Date2016-12-17 18:10 +0100
Message-ID<sPqEG-3ZR-17@gated-at.bofh.it>
In reply to#175772
On Sat 17 Dec 2016 at 17:57:26 (+0200), Lars Noodén wrote:
> On 12/17/2016 05:40 PM, Richard Owlett wrote:
> [...]
> > I don't wish anything but full path to all files in a top level directory.
> > 
> > Followup question how should I found the answer for myself. I looks
> > basic enough ...
> > TIA
> 
> One way would be to use find combined with realpath.
> 
> 	find /media/data -exec realpath "{}" \;
> 
> That's recursive.  If you want only that one directory, limit how deep
> it may go:
> 
> 	find /media/data -maxdepth 1 -exec realpath "{}" \;
> 
> If that's too long to type out each time, you can make a shell alias or
> function that accepts the path as an option and then passes that to find.

To get the format as the OP displayed it, you may also need to pipe
the output through sort.

But bear in mind that, using realpath, the output could have files
rooted all over the place (eg try with /etc/systemd/), so after
sorting them, files that you thought would appear together may well
get separated.

man find   will make a good long read during the Polar Vortex!

Cheers,
David.

[toc] | [prev] | [next] | [standalone]


#175808

FromRichard Owlett <rowlett@cloud85.net>
Date2016-12-18 16:50 +0100
Message-ID<sPLSN-1za-13@gated-at.bofh.it>
In reply to#175775
On 12/17/2016 10:59 AM, David Wright wrote:
> On Sat 17 Dec 2016 at 17:57:26 (+0200), Lars Noodén wrote:
>> On 12/17/2016 05:40 PM, Richard Owlett wrote:
>> [...]
>>> I don't wish anything but full path to all files in a top level directory.
>>>
>>> Followup question how should I found the answer for myself. I looks
>>> basic enough ...
>>> TIA
>>
>> One way would be to use find combined with realpath.
>>
>> 	find /media/data -exec realpath "{}" \;
>>
>> That's recursive.  If you want only that one directory, limit how deep
>> it may go:
>>
>> 	find /media/data -maxdepth 1 -exec realpath "{}" \;
>>
>> If that's too long to type out each time, you can make a shell alias or
>> function that accepts the path as an option and then passes that to find.
>
> To get the format as the OP displayed it, you may also need to pipe
> the output through sort.
>
> But bear in mind that, using realpath, the output could have files
> rooted all over the place (eg try with /etc/systemd/), so after
> sorting them, files that you thought would appear together may well
> get separated.
>
> man find   will make a good long read during the Polar Vortex!

This Vortex won't last long enough.
Several of the responses I've received are opening my eyes to 
what can be done with some straight forward (if not simple) shell 
commands.

[toc] | [prev] | [next] | [standalone]


#175810

Fromemetib <chadbrabec@gmail.com>
Date2016-12-18 19:10 +0100
Message-ID<sPO4h-4qs-13@gated-at.bofh.it>
In reply to#175808
> 
> This Vortex won't last long enough.

it only feels like -40 f where i'm at.

> Several of the responses I've received are opening my eyes to 
> what can be done with some straight forward (if not simple) shell 
> commands.

the beauty of the cli


em

[toc] | [prev] | [next] | [standalone]


#175773

FromThe Wanderer <wanderer@fastmail.fm>
Date2016-12-17 17:00 +0100
Message-ID<sPpyW-34V-13@gated-at.bofh.it>
In reply to#175771

[Multipart message — attachments visible in raw view] — view raw

On 2016-12-17 at 10:40, Richard Owlett wrote:

> ls -R /media/data produces the content but not the NEEDED format.
> 
> I want a list like:
> /media/data/dir1/filea
> /media/data/dir1/fileb
> /media/data/dir1/subdir1/filex
> /media/data/dir1/subdir1/filey
> /media/data/dir1/subdir1/filez
> /media/data/dir2/filea
> /media/data/dir2/fileb
> /media/data/dir2/subdir1/filex
> /media/data/dir2/subdir1/filey
> /media/data/dir2/subdir1/filez
> et cetera
> 
> I don't wish anything but full path to all files in a top level 
> directory.
> 
> Followup question how should I found the answer for myself. I 
> looks basic enough ...

I can't say for sure that ls can't do this, but if I wanted that, I'd
use find.

'find /path/to/directory' produces a list of all nodes (files,
directories, or otherwise) in the specified directory, in exactly the
format you indicate.

Generally, if you want to do something recursively across directories in
an *nix environment, find is the tool to use. Some tools do have
recursiveness options of their own, and occasionally those options are
easier to use or provide better functionality, but in most cases you're
better off going to find as a first resort.

-- 
   The Wanderer

The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man.         -- George Bernard Shaw

[toc] | [prev] | [next] | [standalone]


#175774

FromKushal Kumaran <kushal@locationd.net>
Date2016-12-17 17:10 +0100
Message-ID<sPpIB-3oI-7@gated-at.bofh.it>
In reply to#175771
Richard Owlett <rowlett@cloud85.net> writes:

> ls -R /media/data produces the content but not the NEEDED format.
>
> I want a list like:
> /media/data/dir1/filea
> /media/data/dir1/fileb
> /media/data/dir1/subdir1/filex
> /media/data/dir1/subdir1/filey
> /media/data/dir1/subdir1/filez
> /media/data/dir2/filea
> /media/data/dir2/fileb
> /media/data/dir2/subdir1/filex
> /media/data/dir2/subdir1/filey
> /media/data/dir2/subdir1/filez
> et cetera
>
> I don't wish anything but full path to all files in a top level
> directory.
>

find /media/data -type f

> Followup question how should I found the answer for myself. I looks
> basic enough ...
> TIA

I don't recall now when I first learnt about the find command.  Now I
use it all the time.  The Unix Power Tools book
(http://shop.oreilly.com/product/9780596003302.do) has a chapter on the
find command.  If you have access to an O'Reilly Safari account, you
could browse through it.

-- 
regards,
kushal

[toc] | [prev] | [next] | [standalone]


#175776 — THANK YOU [Re: [Newbie] Can ls command format output my way?]

FromRichard Owlett <rowlett@cloud85.net>
Date2016-12-17 18:20 +0100
SubjectTHANK YOU [Re: [Newbie] Can ls command format output my way?]
Message-ID<sPqOl-44k-1@gated-at.bofh.it>
In reply to#175771
On 12/17/2016 9:40 AM, Richard Owlett wrote:
> ls -R /media/data produces the content but not the NEEDED format.
>
> I want a list like:
> /media/data/dir1/filea
> /media/data/dir1/fileb
> /media/data/dir1/subdir1/filex
> /media/data/dir1/subdir1/filey
> /media/data/dir1/subdir1/filez
> /media/data/dir2/filea
> /media/data/dir2/fileb
> /media/data/dir2/subdir1/filex
> /media/data/dir2/subdir1/filey
> /media/data/dir2/subdir1/filez
> et cetera
>
> I don't wish anything but full path to all files in a top level
> directory.
>
> Followup question how should I found the answer for myself. I
> looks basic enough ...
> TIA
>
>

"find" is what I was looking for.
Browsing the man page suggests I can even select which lines to 
print - i.e. I'm only really in files of form *.html .
Thanks again.

[toc] | [prev] | [next] | [standalone]


#175777

Fromemetib <chadbrabec@gmail.com>
Date2016-12-17 19:00 +0100
Message-ID<sPrr4-4ij-1@gated-at.bofh.it>
In reply to#175771
something else that you could use is 'locate'

it's on most systems nowdays and it updates each night from cron.  it's not as cpu intensive and you can update is quickly with 'updatedb'.

if you're just searching removable media, as in your /media/... example then find would be better.

i prefer locate to find when searching the entire system.

em

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web