How can I check disk space used in a partition using the terminal in Ubuntu 12.04 LTS?

507,840

Solution 1

The su command is completely irrelevant. The disk usage is the same for all users. Anyway, some relevant commands and their output on my system are:

terdon@oregano ~ $ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda7              68G   23G   43G  35% /
udev                   10M     0   10M   0% /dev
tmpfs                 800M  1.6M  798M   1% /run
tmpfs                 5.0M     0  5.0M   0% /run/lock
tmpfs                 3.2G   12M  3.2G   1% /run/shm
/dev/sda6             290G  256G   20G  94% /home
tmpfs                 3.2G  992K  3.2G   1% /tmp
none                  4.0K     0  4.0K   0% /sys/fs/cgroup
/dev/sdc1             466G  379G   88G  82% /media/terdon/Iomega_HDD

For a specific partition:

terdon@oregano ~ $ df -h /dev/sda7
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda7              68G   23G   43G  35% /

Alternatively, though this only lists the size, not the %used:

terdon@oregano ~ $ lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 465.8G  0 disk 
├─sda1   8:1    0  39.2M  0 part 
├─sda2   8:2    0  14.7G  0 part 
├─sda3   8:3    0  78.1G  0 part 
├─sda4   8:4    0     1K  0 part 
├─sda5   8:5    0     2G  0 part 
├─sda6   8:6    0 294.4G  0 part /home
├─sda7   8:7    0  68.7G  0 part /
└─sda8   8:8    0   7.8G  0 part [SWAP]
sdc      8:32   0 465.8G  0 disk 
└─sdc1   8:33   0 465.8G  0 part /media/terdon/Iomega_HDD
sr0     11:0    1  1024M  0 rom  

Conversely, you can use the du command to print directory size which will give you the disk usage of a partition if you run it on a partition's mountpoint: du -xsch /home for example. The -x option will "skip directories on different file systems," which is helpful if you have other mount points nested below the partition's mount point (typically /).

Solution 2

You can use df -Th to get the used space of partitions:

$ df -Th

Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda9      ext4       22G   16G  4.8G  77% /
none           tmpfs     4.0K     0  4.0K   0% /sys/fs/cgroup
udev           devtmpfs  1.5G  4.0K  1.5G   1% /dev
tmpfs          tmpfs     297M  1.4M  295M   1% /run
none           tmpfs     5.0M  4.0K  5.0M   1% /run/lock
none           tmpfs     1.5G  616K  1.5G   1% /run/shm
none           tmpfs     100M   68K  100M   1% /run/user
/dev/sda5      fuseblk    53G   34G   19G  65% /media/Songs
/dev/sda7      fuseblk   103G   90G   14G  88% /media/Data
/dev/sda6      fuseblk    69G   34G   35G  50% /media/Movies
/dev/sda1      fuseblk    49G   36G   14G  72% /media/guru/0C64A7F864A7E326

You can also provide it with a specific partition if you want to view disk utilization of only that partition:

$ df -Th /dev/sda9

Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sda9      ext4   22G   16G  4.8G  77% /

You can also use pydf or discus to get better representation in terminal. You need to install these if you want to use it. Type:

sudo apt-get install pydf in terminal to install pydf.

$ pydf  
Filesystem Size Used Avail Use%                                      Mounted on                  
/dev/sda9   22G  16G 4893M 72.7 [#########################.........] /                           
/dev/sda7  103G  90G   13G 87.2 [##############################....] /media/Data                 
/dev/sda6   69G  34G   35G 49.3 [#################.................] /media/Movies               
/dev/sda5   53G  34G   19G 64.5 [######################............] /media/Songs                
/dev/sda1   49G  35G   14G 71.9 [########################..........] /media/guru/0C64A7F864A7E326

Solution 3

You can easily check disk space status with df -h.

Sometimes you might end up accidentally filling your hard disk via some automated processes you've set up. When that happened to me I needed to find where most of my disk space went. The following command was helpful for that task:

$ cd /
$ sudo du -sh ./*

This gives a list of files and folders in the current directory as well as the size of each one. If a directory is larger than it should be, cd to that directory and run sudo du -sh ./* again. Repeat until you've found what is using up most of your disk space.

Share:
507,840

Related videos on Youtube

Jatttt
Author by

Jatttt

Updated on September 18, 2022

Comments

  • Jatttt
    Jatttt over 1 year

    I am using Ubuntu 12.04 LTS and I was wondering if there is a command that can tell the space used in a partition using the terminal. Like I want to use the su command to change to a user called admin (it is named admin). So I typed :

    su admin
    

    Entered the password

    Now I want to see the disk space used in this partition. So.... Is there is a command fot that?

    • Diogo Gomes
      Diogo Gomes over 5 years
      Can someone remove the duplicate tag? This question is for the terminal.
    • ImtiazeA
      ImtiazeA about 5 years
      lsblk | grep sda should help.
  • Mr.Lee
    Mr.Lee about 10 years
    -h stands for human which makes it readable by us humans, otherwise it will be in bytes ^^
  • mpen
    mpen over 7 years
    pydf is much easier to read. 6/7 of the df -Th entries are confusing garbage.
  • R. Oosterholt
    R. Oosterholt about 7 years
    +1 for the du -xsch /home example; especially -x
  • Arefe
    Arefe over 6 years
    This is helpful
  • David Mauricio
    David Mauricio almost 4 years
    Thanks, i could not install any utility due missing space but with this i could manage to free up some space
  • Charlie Parker
    Charlie Parker over 2 years
    when should one use du vs df?
  • Charlie Parker
    Charlie Parker over 2 years
    the output of df seems like nonsense to me (synthesis) miranda9~ $ du -hs ~/data 59G /home/miranda9/data (synthesis) miranda9~ $ df -h ~/data Filesystem Size Used Avail Use% Mounted on daf-file-01.cs.illinois.edu:/srv/local/home/miranda9 10T 9.7T 365G 97% /home/miranda9 why aren't they matching?
  • terdon
    terdon over 2 years
    @charlie because you are comparing the size of the data subdirectory to the size of the entire remotely mounted volume. Why would they match? For more details, please ask a new question.