Sort by size, then list file in each directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sort by size, then list file in each directory
# 1  
Old 07-01-2009
Sort by size, then list file in each directory

Hi,

I have directories with name like:
aaa
bbb
ccc
...

I would like to to see which directories are the largest and then list the files within each. I have success using:

Code:
du -ks * | sort -rin | head -n 20

which gives me an output like:
120 bbb
27 ccc
3 aaa
...

I would like to be able to do a simple "ls" so I have a clearer view of what's in each of the big directory. Without knowing anything about xargs, I am trying:

Code:
du -ks * | sort -rin | head -n 20 | xargs ls

which gives me (on top of the errors) an alphabetical order list of "ls", instead of what I would like which is more like a "-exec ls {}" in "find"...

ls: 3: No such file or directory
ls: 120: No such file or directory
ls: 27: No such file or directory
aaa:
will_cover_page.gif

bbb:
will_dependents_page_2.gif will_dependents_page_4.gif
will_dependents_page_3.gif

ccc:
will_dependents_page_1.gif will_signatures.gif

Is there a more efficient way of doing this? Thanks in advance...
# 2  
Old 07-01-2009
Code:
find /path/to/directories -type d -size +20 |
while read dirname
     ls -l $dirname
done > outputfile

Change the 20 (blocks) to whatever size suits you.
# 3  
Old 07-01-2009
even this will do i guess...
Code:
find /path/to/directories -type d -size +20 |xargs ls -lrt

# 4  
Old 07-01-2009
For:
Code:
find . -type d -size +2

I get this:
.
./99584B685FF3/bbb.app
./D3B9BA1F472/www.app
./830F3FF6E3F9/Documents
./A754A83053D/www.app
...
For some reason, it finds stuff one directory lower... "99584B685FF3" is the directory I am aiming for, so I tried
Code:
find . -type d -size +2 -maxdepth 1

I get:
. Smilie Shouln't it be something like ./99584B685FF3 Smilie

and for
Code:
find . -type d -size +2 -maxdepth 2

.
./99584B685FF3/bbb.app
./D3B9BA1F472/www.app
./830F3FF6E3F9/Documents
./A754A83053D/www.app
...

What could be the reason. I initially thought directories were just "special files" in UNIX and do not have a size. But the "Documents" shown is really a directory.

Thanks for suggesting but still no go. Furthermore, I am losing all the size sorting - largest directory first

Last edited by ChatPerdu; 07-01-2009 at 06:40 PM.. Reason: wrong info posted
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sort by file/directory size

OS : RHEL 6.6 I want to list the files/directories sorted (Ascending or Desceding) by their size. As you can see in the below example, du command doesn't sort by size. In Linux world, is there any other command or workaround using du command to list the files/directories sorted by their... (6 Replies)
Discussion started by: John K
6 Replies

2. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

3. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

4. UNIX for Dummies Questions & Answers

Command to list our directory size

Is there any command that can list out all the files size including directory in 1 command? `ls` will only give 2048 for a directory, which i'm looking for the actual size. (5 Replies)
Discussion started by: lsy
5 Replies

5. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies

6. Shell Programming and Scripting

Can't sort file by size column

Hello, I've done ls -ls >fileout1 When I do the sort command for +4 it sorts it bu group. When I do +5 it sorts it by date. But it's skipping the file size column. Example: rwxr-xr-x 1 Grueben sup 65 16 Sep 13:58 cdee How can I sort it by file size? It doesn't... (2 Replies)
Discussion started by: Grueben
2 Replies

7. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

8. UNIX for Dummies Questions & Answers

How can I sort the file names in the directory

Hi , I have a list of files in the directory I want to sort based on the file name. But in the middle of filename contains the number based on that I need to sort.Could you suggest me on the same? Example filenames: /user1$ls RS.DEV.ISV.F1.RS.REFDATA.DATA... (1 Reply)
Discussion started by: praveen.thumati
1 Replies

9. Shell Programming and Scripting

File size limitation of unix sort command.

hi , iam trying to sort millions of records which is delimited and i cant able to use sort command more than 60 million..if i try to do so i got an message stating that "File size limit exceeded",Is there any file size limit for using sort command.. How can i solve this problem. thanks ... (7 Replies)
Discussion started by: cskumar
7 Replies

10. UNIX for Dummies Questions & Answers

list file's by size order in sepecfied directory and sub directories

How do I list files of type "*.file" for example by size order recursively ? (2 Replies)
Discussion started by: ferretman
2 Replies
Login or Register to Ask a Question