How can I get the current disk usage (in %) of my hard drive from the command line?
Command-Line – How to Get Disk Usage
command linedisk-usage
Related Solutions
You can mount the drive from command line easily even without creating a folder in /media
as other question suggests.
- Open a terminal
- Type
udisks --mount /dev/sda2
The result?
Your /dev/sda2
will be mounted in the /media/label
, where label
refers to the name of label of the partition. For example, my /dev/sda2
is labeled as Main
, and when i do the command, "/dev/sda2" will be mounted on /media/Main
.
How do i know, My Drive "Drivename"'s sdaX
number ?
You can execute
sudo blkid
command in a terminal to know, which sdaX you have to input.Example: My example run returns this:
anwar@edubuntu-lenovo:~$ sudo blkid /dev/sda1: UUID="01CD4993623F05D0" TYPE="ntfs" /dev/sda2: LABEL="Main" UUID="A80C1BD70C1B9F7E" TYPE="ntfs" /dev/sda3: LABEL="Work" UUID="01CCB271A80A07E0" TYPE="ntfs" /dev/sda5: LABEL="Free" UUID="DE53-CB6B" TYPE="vfat" /dev/sda6: UUID="364126ac-01c9-4dd2-ab19-eecc733a9640" TYPE="ext4" /dev/sda7: UUID="b1537dfc-e918-4fea-9a99-44a034e57429" TYPE="swap" /dev/sda8: UUID="01CD49906DD38770" TYPE="ntfs" /dev/sda9: LABEL="Precise-New" UUID="7c934266-dfcb-45de-879b-e3ceafcd0862" TYPE="ext4"
So i know that, if I wanted to mount "Work", I have to use sda3
.
If the partition has no label:
If your partition has no label, it will be mounted in /media/UUID
, where UUID
refers to the UUID of the partition.
For example: If i mount my /dev/sda8
, which does not have a Label, it will be mounted in /media/01CD49906DD38770
Folder.
Hope this will help.
baobab:
If you want to use baobab, this is possible by mounting the root filesystem in another place and analysing that. This way, other filesystems will not be mounted in the new root mount and any files hidden by mounts under /
will be uncovered and counted in your analysis.
Assuming your root filesystem is on sda1
(df
will tell you which device it is):
mkdir root-rebound
sudo mount /dev/sda1 root-rebound
baobab root-rebound
and then tidy up when you're done:
sudo umount root-rebound
rmdir root-rebound
Alternatively you could unmount said file systems manually. You can also scan just your home folder, because it will most likely contain the source of the excessive disk space usage.
du has two options which are able to prevent counting other filesystems:
-x, --one-file-system skip directories on different file systems --exclude=PATTERN exclude files that match PATTERN
Thus,
du -hx
would ignore all other mounted filesystems or
du -h --exclude /media
would ignore all files in /media
where most filesystems are mounted.
If you're using du
, sorting so that the biggest things appear at the bottom of the list can help decipher the output. eg:
du -hx | sort -h
Best Answer
By using the
df
command.Here's an example output:
Also take a look at its manpage.