LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-30-2007, 11:38 PM   #1
rastiazul
Member
 
Registered: Feb 2006
Location: Costa Rica
Distribution: GalliumOS, Lubuntu
Posts: 84

Rep: Reputation: 15
how to create a list of files and folders (name and size only)


Hello
Please tell me how to create a list of files and folders, the list has to be made of names, extensions, and sizes only, no other information, and sizes should be human readable. Ive spent a a long time trying to do this....


thank you
 
Old 12-30-2007, 11:43 PM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
ls -lh | awk '{print $8 " " $5}'

Example output:

1024_wallpaper.jpg 169K
Desktop 4.0K
Downloads 4.0K
IC 4.0K
Music 12K
PhD 4.0K
Pictures 4.0K
README_PXE.TXT 27K
UKPEW08 4.0K

Last edited by Nylex; 12-30-2007 at 11:44 PM.
 
Old 12-30-2007, 11:46 PM   #3
rastiazul
Member
 
Registered: Feb 2006
Location: Costa Rica
Distribution: GalliumOS, Lubuntu
Posts: 84

Original Poster
Rep: Reputation: 15
thanx but the problem with this command is that it doesnt work if the files have spaces...
 
Old 12-31-2007, 12:08 AM   #4
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
type this

du -h

Sample output

678M ./youtube
20K ./.nautilus/metafiles
552K ./.nautilus
4.0K ./.navicat/dosdevices
28K ./.navicat/Navicat
4.0K ./.navicat/drive_c/Program Files/Common Files
8.0K ./.navicat/drive_c/Program Files
180K ./.navicat/drive_c/windows/inf.done
4.0K ./.navicat/drive_c/windows/temp
4.0K ./.navicat/drive_c/windows/profiles/All Users/Templates

This will give you the file sizes in human readable format and the name of the files including spaces. Unfortunately it prints the full path.
 
Old 12-31-2007, 12:10 AM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
GNU find or stat
Code:
# find /path -type f -printf "%s:%p\n" 
# stat -c "%s:%n" *
standard procedure: check the man page for more info
 
Old 12-31-2007, 12:26 AM   #6
rastiazul
Member
 
Registered: Feb 2006
Location: Costa Rica
Distribution: GalliumOS, Lubuntu
Posts: 84

Original Poster
Rep: Reputation: 15
hmm dv502 thanx but this only gives information about folders, not individual files, the path is alright

ghostdog74:

stat command doesnt give size

find command doesnt give size in human readable format
and also gives full path starting from / but thats a minor detail I guess

Last edited by rastiazul; 12-31-2007 at 12:33 AM.
 
Old 12-31-2007, 12:35 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Code:
stat -c "%n    %s" *
prints name and size for all files in current directory.
Code:
stat -c "%n    %s" dirname/*
prints dirname/name and size for all files in dirname. (Use sed to get rid of dirname in the output.)

For this solution (and anything with ls), you don't get actual directory size. For that, you need something like du.

Maybe you could tell us the overall objective---there might be a better way....
 
Old 12-31-2007, 12:39 AM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by rastiazul View Post
hmm dv502 thanx but this only gives information about folders, not individual files, the path is alright
au contraire---du works on files and folders

Quote:
Originally Posted by rastiazul View Post
stat command doesnt give size
yes it does....

Last edited by pixellany; 12-31-2007 at 12:41 AM.
 
Old 12-31-2007, 12:43 AM   #9
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
Quote:
Originally Posted by rastiazul View Post
hmm dv502 thanx but this only gives information about folders, not individual files
my mistake...
 
Old 12-31-2007, 12:51 AM   #10
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by dv502 View Post
my mistake...
du -a

lists files and directories
 
Old 12-31-2007, 12:52 AM   #11
rastiazul
Member
 
Registered: Feb 2006
Location: Costa Rica
Distribution: GalliumOS, Lubuntu
Posts: 84

Original Poster
Rep: Reputation: 15
its ok


I found a way to do it: since it appears there is no single command that can do everything, Im gonna do it this way:

for i in *; do mv "$i" `echo $i | tr ' ' '.'`; done


ls -lh|awk '{print $5"\t"$9}' > list.txt



Two commands, so its a little more work but not much.

PS: it wasnt me who figure it out haha, someone told me in #linuxlatino

Last edited by rastiazul; 12-31-2007 at 01:05 AM.
 
Old 12-31-2007, 01:00 AM   #12
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
Quote:
Originally Posted by pixellany View Post
du -a

lists files and directories
thanks pixellany

sample output from du -a

1049356 ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VTS_01_3.VOB
12 ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VTS_02_0.VOB
16 ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VIDEO_TS.IFO
439176 ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VTS_04_1.VOB
1049428 ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VTS_01_1.VOB
20 ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VTS_03_0.BUP
1049456 ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VTS_01_2.VOB

I added h for human readable

du -ah

1.1G ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VTS_01_3.VOB
12K ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VTS_02_0.VOB
16K ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VIDEO_TS.IFO
429M ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VTS_04_1.VOB
1.1G ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VTS_01_1.VOB
20K ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VTS_03_0.BUP
1.1G ./tmp/kde-david/k9copy/dvd/VIDEO_TS/VTS_01_2.VOB
 
Old 12-31-2007, 01:03 AM   #13
rastiazul
Member
 
Registered: Feb 2006
Location: Costa Rica
Distribution: GalliumOS, Lubuntu
Posts: 84

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pixellany View Post
du -a

lists files and directories
ohh didnt notice this option when i checked du --help
Good to know, thanx, but Im going to stick with the other 2 commands because it looks better
 
Old 01-01-2008, 04:46 PM   #14
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
Quote:
Originally Posted by rastiazul View Post
its ok


I found a way to do it: since it appears there is no single command that can do everything, Im gonna do it this way:

for i in *; do mv "$i" `echo $i | tr ' ' '.'`; done


ls -lh|awk '{print $5"\t"$9}' > list.txt



Two commands, so its a little more work but not much.

PS: it wasnt me who figure it out haha, someone told me in #linuxlatino
Doing it this way, renames your file(s) that has spaces with dots. But if you want to preserved your files without renaming them, the du -ah is as close to what you wanted in your post, a list of files in human readable file sizes.

Here is something similar to du -ah, it lists
the files in the current directory.
Code:
ls -lh | cut -d' ' -f5,8-
Put a space between the apostrophe. It's not ''

Last edited by dv502; 01-01-2008 at 04:48 PM.
 
Old 01-01-2008, 06:03 PM   #15
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
I have a script somewhere that does the diskdir job, if you d like compatible with windows (except archives).

http://www.totalcmd.net/plugring/diskdir_extended.html

Diskdir is the very best solution for you (try with wine)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create a simple script for installing a list of files zbenjudah Debian 28 04-16-2007 03:03 PM
How do I produce sorted list of files in current directory over a certain size? bangback Linux - Newbie 3 10-25-2006 12:11 AM
Samba can create new files and folders but access denied in any new folders k.king Linux - Networking 2 01-15-2006 06:14 AM
cant save or create files/folders on drives. felonius Linux - Newbie 9 11-07-2004 03:18 PM
how do i limit a folders size? darklordzim Linux - Newbie 1 05-31-2004 06:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration