102

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?

terdon
  • 100,812
Jatttt
  • 2,327
  • 12
  • 32
  • 43

3 Answers3

162

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 /).

terdon
  • 100,812
  • 4
    -h stands for human which makes it readable by us humans, otherwise it will be in bytes ^^ – Mr.Lee Mar 11 '14 at 18:24
  • 1
    +1 for the du -xsch /home example; especially -x – R. Oosterholt Mar 16 '17 at 11:15
  • when should one use du vs df? – Charlie Parker Sep 03 '21 at 16:38
  • 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? – Charlie Parker Sep 03 '21 at 16:39
  • @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. – terdon Sep 04 '21 at 12:53
  • Instead of lsblk command you can also use disktype command. – u_Ltd. Jan 08 '24 at 01:28
  • @u_Ltd. I had not heard of disktype before but after installing it, I see it doesn't seem to report disk usage, only the filesystem type and size. So I don't really see how it would help here. – terdon Jan 08 '24 at 09:25
  • @terdon (I) It helps as much as mentioning lsblk – u_Ltd. Jan 08 '24 at 21:16
  • @terdon (II) Forgotten space: disktype outputs information such as Partition 6: ... (136315928064 bytes, ... and in addition Volume size ... (136314880000 bytes, ... which enables you to calculate remaining bytes at the end of the partition (1 MB, in this case, maybe 1 GB in other cases). Probably not what the OP asked for but helpful anyway. – u_Ltd. Jan 08 '24 at 21:16
  • Ha! Yes, fair enough, lsblk is no more helpful, true, @u_Ltd. – terdon Jan 09 '24 at 00:00
38

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
g_p
  • 18,504
18

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.

Loknar
  • 281