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 Mon 22 Sep 2014, 20:21
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 1 of 2 [18 Posts]   Goto page: 1, 2 Next
Author Message
xan

Joined: 25 Nov 2012
Posts: 49

PostPosted: Thu 03 Oct 2013, 05:02    Post subject:  What's best way to extract file names from a folder?
Subject description: into a text file
 

If I have many files in a folder is there a good way to get all the file names, dates and sizes into a text file?

I don't have any background using Linux so only know basic commands.

Best I have figured out so far is:
ls --color -gGh

but there must be a better way.
Back to top
View user's profile Send private message 
nic007

Joined: 13 Nov 2011
Posts: 725

PostPosted: Thu 03 Oct 2013, 06:12    Post subject: Re: What's best way to exctract a file names from a folder?  

xan wrote:
If I have many files in a folder is there a good way to get all the file names, dates and sizes into a text file?

I don't have any background using Linux so only know basic commands.

Best I have figured out so far is:
ls --color -gGh

but there must be a better way.


I'm sure someone will give you the complete solution for all file attributes but you can quickly get a list of the file names and sizes. Using ROX, click on the folder and then select all files. Right-click and chose count from menu. You can copy the result to a text editor.
Back to top
View user's profile Send private message 
Burn_IT


Joined: 12 Aug 2006
Posts: 1010
Location: Tamworth UK

PostPosted: Thu 03 Oct 2013, 07:30    Post subject:  

In Windows it would be:
DIR x:\folder -> y:\dir.TXT

I assume the redirection is available in Puppy as well (I'll try next time I'm at home)

_________________
I can't remember the last time I forgot something!
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Thu 03 Oct 2013, 07:39    Post subject:  

Code:
for i in * ; do stat -c %n' '%s' '%x' '%y' '%z $i  >>files_stats.text; done
Back to top
View user's profile Send private message Visit poster's website 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Thu 03 Oct 2013, 08:05    Post subject: Re: What's best way to exctract a file names from a folder?  

xan wrote:
... into a text file?...


> textfile Very Happy

Code:
ls -la > textfile
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2247

PostPosted: Sat 05 Oct 2013, 03:33    Post subject:  

It's not really a good idea to use ls to list files -it will not work if there are spaces in any of the names. The expansion of '*' by the shell does work accurately though, and saves an external call.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 398
Location: Japan

PostPosted: Sat 05 Oct 2013, 05:22    Post subject:  

amigo wrote:
It's not really a good idea to use ls to list files -it will not work if there are spaces in any of the names.
??? Seems to work nicely. It's Karl's code that has problems with spaces.
Back to top
View user's profile Send private message 
musher0


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

PostPosted: Sat 05 Oct 2013, 15:43    Post subject:  

Hello, xan.

Basically, you're very close. I would suggest the following:

For a screen by screen listing:
Code:
ls --color -og ~ | more

This retains the color coding for the file types. The "-og" parameters
create a semi-long listing. It's like the "-la" parameters, but without the
two "ownership" columns.

For a file listing:
Code:
ls --color=never -og ~ > files.lst

In addition to the above, the "--color=never" parameter removes all
color coding. In a file, color codings make the listing difficult to read,
because they incorporate the "Escape" color codes in the file.

Of course, you would change the wiggle "~" (which is bash short-hand
for "/root") to your desired folder -- or omit it altogether if you only
want the listing for the directory you are already in.

Another example. If you want a listing of all folders and files in your /root
folder, the command would be, assuming that you are already in /root:
Code:
ls --color=never -og * > all-files.lst


Afterwards, if you want to easily read back and forth through the file to
see what files and folders you have, you could issue the command:
Code:
less all-files.lst

You then use "G" or "g" to go to the bottom or the top of the text file,
"u" or "d" to go up or down. You'd press "F1" for the less help file, which
will suggest to you some other letters for browsing through your file.

As a reminder, if you just want a one column listing, with only the file
name, the parameter is
Code:
ls -1

(The number, "1"; not the letter, "l".)

I hope this helps.

Best regards.

musher0
color_never.jpg
 Description   
 Filesize   55.33 KB
 Viewed   230 Time(s)

color_never.jpg


_________________
"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 
xan

Joined: 25 Nov 2012
Posts: 49

PostPosted: Sat 05 Oct 2013, 22:33    Post subject:  

musher0 wrote:

Code:
ls --color -og | more



Thanks for all the suggestions people.

Is there a way to omit the permissions column from the results?

I found a suggestion to use awk but I don't understand it and it doesn't handle spaces in file names.

Code:
ls --color -ogh | awk '{ print $3, $4, $6 }'
Back to top
View user's profile Send private message 
6502coder

Joined: 23 Mar 2009
Posts: 86
Location: Western United States

PostPosted: Sun 06 Oct 2013, 00:03    Post subject:  

To omit the permissions fields, try

Code:
ls  --color  -ogh  | cut  --characters=11-
Back to top
View user's profile Send private message 
musher0


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

PostPosted: Sun 06 Oct 2013, 11:51    Post subject:  

6502coder wrote:
To omit the permissions fields, try

Code:
ls  --color  -ogh  | cut  --characters=11-


Personally, I'd go with:
Code:
ls --color -ogh | cut -d" " -f3-12

It starts with the size and includes the target of the links as well.

But, this is obviously fine-tuning. Smile Cool

BFN.

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 
MochiMoppel


Joined: 26 Jan 2011
Posts: 398
Location: Japan

PostPosted: Wed 09 Oct 2013, 23:05    Post subject:  

musher0 wrote:
It starts with the size and includes the target of the links as well.

But for no obvious reasons - like in your screenshot - includes year instead of time on some files:
Code:
4.0K Aug  2  2011 pup_420
4.0K Oct  4 12:09 pup_lazy
4.0K Jul 12  2012 pup_lucid528
4.0K Oct  1 11:06 pup_precise
4.0K Aug 21 11:34 pup_raring
Back to top
View user's profile Send private message 
musher0


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

PostPosted: Wed 09 Oct 2013, 23:28    Post subject:  

MochiMoppel wrote:
musher0 wrote:
It starts with the size and includes the target of the links as well.

But for no obvious reasons - like in your screenshot - includes year instead of time on some files:
Code:
4.0K Aug  2  2011 pup_420
4.0K Oct  4 12:09 pup_lazy
4.0K Jul 12  2012 pup_lucid528
4.0K Oct  1 11:06 pup_precise
4.0K Aug 21 11:34 pup_raring


Hello, MochiMoppel.

Thanks for your input.

I noticed that too. It seems to be coded in the "ls" program.
Maybe if it's the current year, it indicates the time?
It's the only logic I see at present.

BFN.

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 
MochiMoppel


Joined: 26 Jan 2011
Posts: 398
Location: Japan

PostPosted: Thu 10 Oct 2013, 05:38    Post subject:  

musher0 wrote:
It's the only logic I see at present.
You see logic? Laughing

Here some more ideas
Code:
find /root/ -maxdepth 1 -printf "%TY-%Tm-%Td %TH:%TM\t%s\t%h/%f\n"
2013-10-10 16:32   520   /root/root/
2013-10-10 14:09   799   /root/list
2013-10-10 14:06   25   /root/tmp.txt
2013-10-10 11:20   60   /root/.macromedia
2013-10-10 11:20   60   /root/.adobe
2013-10-10 11:17   23347   /root/.jwmrc
2013-10-10 11:17   23347   /root/.jwmrc-previous
2013-10-10 11:18   160   /root/.wine
2013-10-10 11:17   80   /root/.packages

Can't display just seconds, it's always split seconds:
Code:
find /root/ -maxdepth 1 -printf "%TY-%Tm-%Td %TH:%TM:%TS\t%s\t%h/%f\n"
2013-10-10 16:32:55.8519607360   520   /root/root/
2013-10-10 14:09:29.8225191960   799   /root/list
2013-10-10 14:06:46.0334179900   25   /root/tmp.txt
2013-10-10 11:20:42.3953408790   60   /root/.macromedia
2013-10-10 11:20:42.3386745240   60   /root/.adobe
2013-10-10 11:17:59.3995686430   23347   /root/.jwmrc
2013-10-10 11:17:52.5662728070   23347   /root/.jwmrc-previous
2013-10-10 11:18:35.8527019420   160   /root/.wine
2013-10-10 11:17:53.5096009640   80   /root/.packages

Getting rid of the split seconds:
Code:
find /root/ -maxdepth 1 -printf "%TY-%Tm-%Td %TH:%TM:%TS\t%s\t%h/%f\n" | sed 's/\.[0-9]*//'
2013-10-10 16:32:55   520   /root/root/
2013-10-10 14:09:29   799   /root/list
2013-10-10 14:06:46   25   /root/tmp.txt
2013-10-10 11:20:42   60   /root/.macromedia
2013-10-10 11:20:42   60   /root/.adobe
2013-10-10 11:17:59   23347   /root/.jwmrc
2013-10-10 11:17:52   23347   /root/.jwmrc-previous
2013-10-10 11:18:35   160   /root/.wine
2013-10-10 11:17:53   80   /root/.packages


There must be easier ways ...
Back to top
View user's profile Send private message 
musher0


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

PostPosted: Thu 10 Oct 2013, 12:10    Post subject:  

MochiMoppel,

If you have complaints about how find or ls performs, the best way
is to address them to the respective author(s). This is not the place.

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 1 of 2 [18 Posts]   Goto page: 1, 2 Next
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.0967s ][ Queries: 12 (0.0041s) ][ GZIP on ]