Go Back   The macosxhints Forums > OS X Help Requests > UNIX - Newcomers



Reply
 
Thread Tools Rate Thread Display Modes
Old 06-12-2009, 12:36 AM   #1
jwriter
Triple-A Player
 
Join Date: May 2007
Posts: 144
script to find largest files on system

1) How can I get a list of say the 20 largest files on my system (hidden, system, whatever)?

2) Same for 20 largest folders?

thank you
jwriter is offline   Reply With Quote
Old 06-12-2009, 01:04 AM   #2
acme.mail.order
League Commissioner
 
Join Date: Sep 2003
Location: Tokyo
Posts: 6,334
for files: (replace the obvious with the size limit you want)

find / -type f -size +20M

for directories:

du | sort -n | tail -30
acme.mail.order is offline   Reply With Quote
Old 06-12-2009, 01:29 AM   #3
jwriter
Triple-A Player
 
Join Date: May 2007
Posts: 144
Quote:
Originally Posted by acme.mail.order

for directories:

du | sort -n | tail -30

This is very cool, largest folders listed by size.

Quote:
Originally Posted by acme.mail.order
for files: (replace the obvious with the size limit you want)

find / -type f -size +20M

I am getting this error...

blah:~ G4$ find / -type f -size +200M
find: -size: +200M: illegal trailing character

Forgive my lack of Unix knowledge - am I entering the file size correctly?
jwriter is offline   Reply With Quote
Old 06-12-2009, 02:27 AM   #4
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
Quote:
Originally Posted by jwriter
blah:~ G4$ find / -type f -size +200M
find: -size: +200M: illegal trailing character

It seems to complaining about the "M" - but that should be fine.
Two ideas:

1) Maybe there is some strange invisible character that you inadvertently typed. Maybe just try typing it in again.
If you can reproduce the problem, or if you still have the command you previously entered on your screen, then copy & paste it and then edit the command-line to insert "echo " (without the quotes) at the beginning and add the following at the end (copy & paste it from here into your Terminal):

| hexdump -C

(I.e. the command should look like:

echo find / -type f -size +200M | hexdump -C

Finally, press Return to execute that command, then copy & paste the command and its results back here so we can see.

2) Maybe you have some other (non-Apple-supplied) version of 'find' that doesn't take such arguments.
See what you get from:

command -V find
__________________
hayne.net/macosx.html

Last edited by hayne; 06-12-2009 at 02:29 AM.
hayne is offline   Reply With Quote
Old 06-12-2009, 02:45 AM   #5
jwriter
Triple-A Player
 
Join Date: May 2007
Posts: 144
Quote:
Originally Posted by hayne
(I.e. the command should look like:

echo find / -type f -size +200M | hexdump -C

What I got was...
Code:
blah:~ G4$ echo find / -type f -size +200M  | hexdump -C
00000000  66 69 6e 64 20 2f 20 2d  74 79 70 65 20 66 20 2d  |find / -type f -|
00000010  73 69 7a 65 20 2b 32 30  30 4d 0a                 |size +200M.|
0000001b
blah:~ G4$
I'm wondering about the period after the M.

Last edited by hayne; 06-12-2009 at 03:27 AM. Reason: code tags
jwriter is offline   Reply With Quote
Old 06-12-2009, 02:54 AM   #6
jwriter
Triple-A Player
 
Join Date: May 2007
Posts: 144
Quote:
Originally Posted by hayne
2) Maybe you have some other (non-Apple-supplied) version of 'find' that doesn't take such arguments.

It seems to run like this...

blah:~ G4$ find / -type f -size +200000000

except I get a lot of permission denied, such as...

find: /private/var/db/shadow: Permission denied
find: /private/var/db/Spotlight-V100: Permission denied
find: /private/var/db/TokenCache: Permission denied

Should I use sudo?
jwriter is offline   Reply With Quote
Old 06-12-2009, 03:31 AM   #7
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
Quote:
Originally Posted by jwriter
Code:
blah:~ G4$ echo find / -type f -size +200M  | hexdump -C
00000000  66 69 6e 64 20 2f 20 2d  74 79 70 65 20 66 20 2d  |find / -type f -|
00000010  73 69 7a 65 20 2b 32 30  30 4d 0a                 |size +200M.|
0000001b
blah:~ G4$
I'm wondering about the period after the M.

That period is what 'hexdump' outputs for non-displayable characters.
The character after the M is a newline character. (hexadecimal 0A is \n)
I'm not sure how you got that into the command. Normally a newline character (entered via the Return key) shows up as a new line.

Have you tried just retyping the command-line?
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 06-12-2009, 04:05 AM   #8
acme.mail.order
League Commissioner
 
Join Date: Sep 2003
Location: Tokyo
Posts: 6,334
Quote:
Originally Posted by jwriter
blah:~ G4$ find / -type f -size +200M
find: -size: +200M: illegal trailing character
Forgive my lack of Unix knowledge - am I entering the file size correctly?

The command is correct as-is. You've inadvertently copied something else.

There are various GUI utilities to do things like this. If you are looking to clear some space then searching for the biggest single files won't help much (unless you've got tons of media). Removing additional languages clears up nearly a gigabyte and unneeded printers is about the same - both resources are distributed across the filesystem.
acme.mail.order is offline   Reply With Quote
Old 06-12-2009, 04:33 AM   #9
baf
MVP
 
Join Date: Jun 2007
Location: Skellefteċ, Sweden
Posts: 1,173
find differs between tiger and leopard. jwriter if you are still running tiger then +20M is not supported. you must use:
-size n[c]
True if the file's size, rounded up, in 512-byte blocks is n. If n is followed by a c, then the primary is true if the file's size is n bytes (characters).
__________________
/Bengt-Arne Fjellner IT-Administrator Luleċ university, Sweden.
Some say: "You learn as long as you live".
My way: "You live as long as you learn".
baf is offline   Reply With Quote
Old 06-12-2009, 11:46 AM   #10
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,263
Quote:
Originally Posted by hayne
The character after the M is a newline character. (hexadecimal 0A is \n)
I'm not sure how you got that into the command. Normally a newline character (entered via the Return key) shows up as a new line.

that's a copy/paste error - one of the annoying things about copying out of Safari is that it tends to include any html newlines when you copy, unless you're really careful with your selection. happens to me all the time.
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Old 06-12-2009, 02:35 PM   #11
jwriter
Triple-A Player
 
Join Date: May 2007
Posts: 144
Quote:
Originally Posted by acme.mail.order
If you are looking to clear some space then searching for the biggest single files won't help much (unless you've got tons of media). Removing additional languages clears up nearly a gigabyte and unneeded printers is about the same - both resources are distributed across the filesystem.

Thanks to all who helped with this. I understand this is not a good way to find likely candidates for clearing space - I will look at the printers and localization. But this was helpful for the future in case I need to copy commands out of a browser. Thanks again.
jwriter is offline   Reply With Quote
Old 06-12-2009, 03:29 PM   #12
yellow
Moderator
 
Join Date: Jan 2002
Posts: 10,677
You might try OmniDiskSweeper instead..
yellow is offline   Reply With Quote
Old 06-13-2009, 08:04 AM   #13
ghostdog74
Triple-A Player
 
Join Date: May 2007
Posts: 78
Code:
ls -laR /home | awk '
/total/{next}
/^\.$/{next}
/^\.\.$/{next}
/^\// && f{f=0}
/^\//{        
    f=1
    gsub(/:$/,"")
    old=$0          
    next
}
f && $1 ~/^-/{
   # for files
   $1=$2=$3=$4=$6=$7=$8=""     
   m=split($0,s , " ")
   size=s[1]
   fold = old "/" s[2]
   print size,fold 
}' | sort -rn|head -20
ghostdog74 is offline   Reply With Quote
Old 06-24-2009, 10:03 PM   #14
smninos
Prospect
 
Join Date: Mar 2009
Posts: 13
So, why is this available as a search option via Finder if it doesn't actually work? The minute you (I) enter the size of the folder I am searching for all the results that were showing up, disappear? It does work for files, just not folders. Am I missing something?
smninos is offline   Reply With Quote
Old 06-30-2009, 08:17 AM   #15
Kirok
Registered User
 
Join Date: Jun 2009
Posts: 1
Not sure if this is still alive and it seems to answered already but what I use is

BLOCKSIZE=1048576; du -x | sort -nr | head -10
Kirok is offline   Reply With Quote
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

Forum Jump



All times are GMT -5. The time now is 11:10 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.