|
|
#1 |
|
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 |
|
|
|
|
|
#2 |
|
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 |
|
|
|
|
|
#3 | ||||||||||||||||||||||||||||||||||||||||||||||
|
Triple-A Player
Join Date: May 2007
Posts: 144
|
This is very cool, largest folders listed by size.
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? |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
#4 | |||||||||||||||||||||||
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
|
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. |
|||||||||||||||||||||||
|
|
|
|
|
#5 | |||||||||||||||||||||||
|
Triple-A Player
Join Date: May 2007
Posts: 144
|
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$ Last edited by hayne; 06-12-2009 at 03:27 AM. Reason: code tags |
|||||||||||||||||||||||
|
|
|
|
|
#6 | |||||||||||||||||||||||
|
Triple-A Player
Join Date: May 2007
Posts: 144
|
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? |
|||||||||||||||||||||||
|
|
|
|
|
#7 | |||||||||||||||||||||||
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 32,473
|
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 |
|||||||||||||||||||||||
|
|
|
|
|
#8 | |||||||||||||||||||||||
|
League Commissioner
Join Date: Sep 2003
Location: Tokyo
Posts: 6,334
|
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. |
|||||||||||||||||||||||
|
|
|
|
|
#9 |
|
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". |
|
|
|
|
|
#10 | |||||||||||||||||||||||
|
Hall of Famer
Join Date: Apr 2007
Posts: 4,263
|
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- |
|||||||||||||||||||||||
|
|
|
|
|
#11 | |||||||||||||||||||||||
|
Triple-A Player
Join Date: May 2007
Posts: 144
|
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. |
|||||||||||||||||||||||
|
|
|
|
|
#12 |
|
Moderator
Join Date: Jan 2002
Posts: 10,677
|
You might try OmniDiskSweeper instead..
|
|
|
|
|
|
#13 |
|
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
|
|
|
|
|
|
#14 |
|
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?
|
|
|
|
|
|
#15 |
|
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 |
|
|
|
![]() |
|
|