SUSE Conversations


How to get a sorted list of large space used files/directories in SLED/SLES



By: dhardik

August 29, 2008 1:10 pm

Reads:1242

Comments:0

Rating:0

Problem: Sometimes, you will find that your home/root partition on your SLED/SLES is getting full. So you have to delete some junk files/directories from your home/root partitions, but problem is how will you find a list of large space used files/directories? Here we go…

We can find the sorted list of large space used files/directory in SLES/SLES using CLI (Command Linux Interface).

Step – 1

Launch ‘gnome-terminal’ for CLI (Command Line Interface) like ‘cmd’ in windows.

Step – 2

You can view your overall disk usage by ‘du’ command.

person@NOVELLDESK:~> df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              32G   32G   0G 100% /
udev                 1006M  156K 1006M   1% /dev
/dev/sda1              33G   11G   22G  33% /windows/C
/dev/sda5              32G   11G   22G  33% /windows/D
/dev/sda6              50G   21G   29G  43% /home
person@NOVELLDESK:~>

The above information shows that my root partition is utilizing 100% disk space. Now, we have to find the sorted list of large space used files/directories so I can delete it if it’s junk for me.

Step – 3

So, here is the command…

person@NOVELLDESK:~> sudo time du -ah /  | uniq |  grep "^[0-9]*[G]" | sort -g -n
du: `/var/lib/ntp/proc/4824/task': No such file or directory
du: `/var/lib/ntp/proc/4824/fd': No such file or directory
du: `/proc/4824/task': No such file or directory
du: `/proc/4824/fd': No such file or directory
11G     /windows
11G     /windows/C
13G     /home/person/XXX
17G    /tmp/rMD-session-6531
22G     /home
22G     /home/person
49G     /
Command exited with non-zero status 1
1.21user 9.90system 3:27.42elapsed 5%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (0major+2820minor)pagefaults 0swaps
person@NOVELLDESK:~>

Now, from the output, we can see that junk file with path /tmp/rMD-session-6531 uses 17 GB of my root partition. We can delete it using the ‘rm’ command after doing double check.

person@NOVELLDESK:~>rm -rf  /tmp/rMD-session-6531

Notes:

  1. In command “grep “^[0-9]*[X]” ” you can replace ‘X’ with ‘G’ ‘K’ and ‘M’, according to your needs to get File/Directory in Gigabytes,Kilobytes and Megabytes sizes.
  2. You can observe errors on the screen, that you can redirect to some file for later observation. For this requirement, our new command would be:
    person@NOVELLDESK:~> sudoo time du -ah /  2> errors.txt| uniq |  grep "^[0-9]*[G]" | sort -g -n
    
  3. If you want a Top 10 sorted list of large space used files/directories Gigabytes sizes, then you can use the below magic command. Also follow note 1 for, Kilobytes and Megabytes sizes.
    sperson@NOVELLDESK:~>udo du -ah /tmp 2> errors.txt  | uniq |  grep "^[0-9]*[G]" | sort -r -g -n | head -n10
    

That’s all for now…

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Tags:
Categories: SUSE Linux Enterprise Desktop, SUSE Linux Enterprise Server, Technical Solutions

Disclaimer: As with everything else at SUSE Conversations, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.

Comment

RSS