$ Linux Commands

Disk Usage — Storage and filesystem information

du Disk Usage

Estimate file and directory space usage

du [OPTIONS] [PATH]
du -sh /var/log
du -sh *
du -h --max-depth=1 /home
-s summary total only
-h human-readable
--max-depth N limit depth
-a all files, not just directories

du -sh * in a directory gives you a quick size overview of each item.

lsof Disk Usage

List open files and the processes using them

lsof [OPTIONS]
lsof -i :80
lsof -u alice
lsof /var/log/syslog
-i PORT files using a network port
-u USER files opened by user
-p PID files opened by process

Useful to find what process is using a port: lsof -i :8080

mount Disk Usage

Mount a filesystem

mount [OPTIONS] DEVICE MOUNTPOINT
mount /dev/sdb1 /mnt/usb
mount -t ntfs /dev/sdb1 /mnt/usb
mount | grep sdb
-t TYPE filesystem type (ext4, ntfs, vfat)
-o opts mount options (ro, rw)
umount Disk Usage

Unmount a filesystem

umount MOUNTPOINT|DEVICE
umount /mnt/usb
umount /dev/sdb1
-f force unmount
-l lazy unmount (detach when not busy)