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 Thu 31 Jul 2014, 07:31
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 [18 Posts]   Goto page: Previous 1, 2
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 336
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.

Proposal:
Code:
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 
amigo

Joined: 02 Apr 2007
Posts: 2226

PostPosted: Mon 14 Oct 2013, 04:11    Post subject:  

Karl was nearly right -except for not double-quoting the file name:
Code:
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.
Code:
for i in * ; do
 case "$i" in
  *'*') : ;;
  *)
   stat -c %n' '%s' '%x' '%y' '%z "$i"  >>files_stats.text
  ;;
 esac
done
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 4229
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,

musher0

_________________
"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 poster's website 
Display posts from previous:   Sort by:   
Page 2 of 2 [18 Posts]   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 post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


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