OpenSUSE Linux Tips, tricks, how-tos, opinions, and news
My Resume - My LinkedIn ProfileWhen you’re in the trenches, pounding out solutions, it’s nice to have any added advantage that you can. Finding the source of what is taking up all the space on a given Linux partition may just find itself on your priority list some day. And when you need to know right now where it is, it’s great to have the following solutions.
Should you need to find the source of what is taking up the space on one of your Linux boxen, you can use this command to get you through:
stage:/ # du -s * | sort -g 0 proc 0 sys 4 media 4 mnt 16 lost+found 68 tmp 100 srv 112 dev 2564 home 7568 bin 9280 sbin 9916 boot 28528 etc 70844 lib 209624 var 221708 root 429396 opt 1848788 VM 2686844 usr stage:/ # |
So now obviously, my /usr path is taking up the most space. Let’s head into /usr and run the command again:
stage:/ # cd usr stage:/usr # du -s * | sort -g 0 tmp 12 X11R6 16 i586-suse-linux 76 local 3404 games 12124 include 18100 sbin 100424 bin 331616 src 1103240 share 1117832 lib stage:/usr # |
We then see that /var/lib and /var/share are taking up the most space.
Once you find the culprits, you can archive them, back them up, truncate them, or just plain rm them (please use ‘rm’ with care).
Also, if you are looking for all files on your drive larger than a certain size, the following script may be useful to you. Don’t forget to ‘chmod +x’ it to make it executable:
#!/bin/sh # In kilobytes on older machines MINSIZE=1000 IFS=$'\\n' # Find the files and put them in a list FILELIST=`find . -size +"$MINSIZE"k -print` for FILE in $FILELIST ; do FILESIZE=`stat \-\-format=%s "$FILE"` FILEM=$(echo "scale=2;$FILESIZE/1048576" | bc -l) printf ""$FILE"\\n" printf "\\tsize is "$FILEM" Megabytes\\t" printf "\\ttype is `file -b "$FILE"`\\n\\n" done |
You may ask, “What is this IFS thing?” Well, it is explained quite well on tldp.org. But for those of us who don’t want to go read that, I’ll just copy and paste the important part for ya’ll:
internal field separator
This variable determines how Bash recognizes fields, or word boundaries, when it interprets character strings.
In other words, bash by default uses spaces to separate things into lists. You are telling it to split the list of files up by the \n or carriage return character rather than by spaces.
Anyway, use the command demonstrated above, and the bash script demonstrated below, to find the files that are taking up all your space.
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
« Dec | Feb » | |||||
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
59 queries. 0.748 seconds