tips
18 tips Disk usage
One command, setting or habit at a time about Disk usage: what it does, the line to copy and a caveat or two.
Disk usage 18
-
Includes dot folders like .cache in a du overview, where the usual glob leaves them out.
du -sh -- .[!.]* * 2>/dev/null | sort -h -
Hide the hundreds of small folders and see only the ones worth cleaning up.
du -h -t 1G /srv | sort -h -
Gives one total for a set of matching files, like all logs or all ISO images.
du -ch /var/log/*.log | tail -n 1 -
Measures a folder without the parts you don't care about, like ISO files or node_modules.
du -sh --exclude=node_modules --exclude='*.iso' ~/projects -
Prints only the columns of df that you list, such as mount point, percentage and inode use.
df -h --output=source,fstype,size,used,avail,pcent,target -
Totals folder sizes without crossing into other mounted filesystems.
sudo du -xh -d1 / | sort -h -
Counts files per directory instead of bytes, to find what exhausts the inodes.
sudo du --inodes -x -d2 /var | sort -n | tail -
Adds the date of the latest change to each folder in a du listing.
du -h -d1 --time --time-style=long-iso ~/Downloads | sort -h -
Shows the size a file claims to be next to the space it really uses on disk.
truncate -s 10G test.img -
Lists deleted files that a running program still holds open, which is why df stays full.
sudo lsof +L1 -
Shows disk usage as a navigable list, biggest first, with delete built in.
ncdu -x / -
Lists every folder in the current directory with its size, sorted so the biggest ones are at the bottom.
du -sh * 2>/dev/null | sort -h -
Lists directory sizes with the biggest last, so you see what fills the disk.
sudo du -h -d1 -x /var | sort -h -
Trims all mounted filesystems that support it, which keeps SSD write speed up.
sudo fstrim -av -
Measures how fast a disk reads sequentially, as a quick health and cabling check.
sudo hdparm -tT /dev/sda -
Lists the processes currently reading or writing the disk, with accumulated totals.
sudo iotop -oPa -
Prints per-disk utilisation and wait times every second to show whether storage is the bottleneck.
iostat -xz 1 -
Shows how many inodes are used on each filesystem, which explains a disk that is full with free space left.
df -i /var
Nothing in this filter yet.