OpenSUSE Linux Rants

OpenSUSE Linux Tips, tricks, how-tos, opinions, and news

My Resume  -  My LinkedIn Profile

January 25, 2008

Linux commands for “What is taking up all my space?”

by @ 6:49 am. Filed under bash, command-line, General Linux, How-To, Linux tips

Terminal Icon

When 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.

3 Responses to “Linux commands for “What is taking up all my space?””

  1. Steve Neidinger Says:

    You can also use the find command to locate files larger than a specified size. This locates files larger than 1 MB (using Suse):

    find / -size +1M

    The plus sign denotes ‘larger than’, and a minus sign would denote ‘smaller than’. See your man page for more details.

  2. Marcus Meissner Says:

    there are very nice gui tools, like kdirstat to help here….

  3. Lamby Says:

    IFS is not specific to the Bash shell.

Leave a Reply

OpenSUSE Linux Rants
Official OpenSUSE Linux Site

internal links:

categories:

SUSE Resources

search blog:

archives:

July 2018
S M T W T F S
« Feb    
1234567
891011121314
15161718192021
22232425262728
293031  

62 queries. 1.344 seconds