Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 24 May 2015, 11:29
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
What's best way to extract file names from a folder?
Moderators: Flash, Ian, JohnMurga
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 2 of 2 Posts_count   Goto page: Previous 1, 2
Author Message

Joined: 26 Jan 2011
Posts: 671
Location: Japan

PostPosted: Mon 14 Oct 2013, 03:03    Post_subject:  

I have no complaints and I didn't complain. Find works nicely and though ls looks odd to me and I was wondering how this might be useful, I don't see this as a "complaint". I know now this behaviour can be changed, that it depends on the version and is an intended feature (files older than 6 months can be displayed with a different time format).

Unfortunately Puppy uses different versions of ls (Lucid uses 7.4, Precise 8.13 etc.). They differ in their defaults (7.4 uses time-style=long-iso, 8.13 time-style=locale) which makes it difficult to propose a short command as I don't know the OP's Puppy version. Bottomline: Parameters should be explicitly set and not taken for granted.

To omit the permissions column from the results: Cut doesn't work reliably. The last column seems to be the number of first-level subdirectories, which may be more than 9, in which case the number of space delimiters may increase...
I would still go with sed here. It's much more flexible.

ls --color=never --group-directories-first  --time-style=long-iso  -Aogp  | sed 's/^[^0-9]*[0-9]* //'
Back to top
View user's profile Send_private_message 

Joined: 02 Apr 2007
Posts: 2365

PostPosted: Mon 14 Oct 2013, 04:11    Post_subject:  

Karl was nearly right -except for not double-quoting the file name:
for i in * ; do stat -c %n' '%s' '%x' '%y' '%z "$i"  >>files_stats.text; done

ls will definitely fail when there are spaces in paths -but I think it's always been a will-not-fix sort of feature/bug for the authors. Anyway, using shell globbing (*) is more efficient. Using stat is straightforward, but you could conceivably us ls for it there -just for one file at a time. Uh, don't forget to doublequote the file name LOL.

You could even use a tar pipeline to generate the info. But, the output from both tar and ls will still need parsing to cull out unwanted items. stat gives finer control.

What's the fastest way? Time them if you like. The real issue is that it work right and be available on the target system. Another drawback to using 'ls' is the differing features among implementations. If you use advanced options which work with ls from coreutils, it may not behave the same using ls from busybox, toybox or whatever.

If your really a compatibility freak, then stat is not the way either, as it is linux-only.
Practically speaking, using stat is the cleanest way to get the, well, stats of each file. And using builtin globbing is faster than call find, ls or whatever. However, there is a caveat for the above code -in the case of an empty directory, where ls would return nothing, globbing will return a '*'. So, it must be eliminated -which needs an extra step.
for i in * ; do
 case "$i" in
  *'*') : ;;
   stat -c %n' '%s' '%x' '%y' '%z "$i"  >>files_stats.text
Back to top
View user's profile Send_private_message 

Joined: 04 Jan 2009
Posts: 5326
Location: Gatineau (Qc), Canada

PostPosted: Tue 15 Oct 2013, 23:38    Post_subject:  

Hi, MochiMoppel.

Yours may not be an "official" complaint. However, the shortcomings
would not have been exposed on this thread if there was not a feeling of
some kind of dissatisfaction about the lack of a standard on the subject of
reporting file sizes.

It is certainly laudable to come up with expert suggestions here on how to
overcome those shortcomings, -- and we can continue doing so until the
cows come home --, but the fact will remain that we have no control on
the next versions of either ls or find. So, how do we draw the authors'
attention, if not by sending them some kind of "complaint"? Or "lament"?
Is "protest" too strong a word? Ok, maybe "a suggestion for
improvement" is a more positive expression.

I hope you see my point. In any case, my comments were never and are
not meant to be personal, far from it. English is not my native language;
please forgive me if some part of my previous post has lent itself to an
interpretation with that "tonality".

Best regards,


"Logical entities must not be multiplied needlessly." / "Il ne faut pas multiplier les êtres logiques inutilement." (Ockham)
Back to top
View user's profile Send_private_message Visit_website 
Display_posts:   Sort by:   
Page 2 of 2 Posts_count   Goto page: Previous 1, 2
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot attach files in this forum
You can download files in this forum

Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0776s ][ Queries: 13 (0.0293s) ][ GZIP on ]