Table of Contents
Disk, Partition, File System
Disk
A disk is a block device.
fdisk
Used to manage partitions on a disk.
$ sudo fdisk -l # list partitions $ sudo fdisk -l | sed -e '/Disk \/dev\/loop/,+5d' # ignore Snap loop mounts
df
$ df -T # disk filesystem format type $ df -H | grep -v ^/dev/loop # ignore Snap loop mounts
Note on Snap Loop Mounts
In addition to listing disks and partitions, fdisk and df also list loop mounts. A loop mount looks like a disk but is in fact a file containing a file system, created by a Snap package install. The Snap package system is proprietary to Canonical. It is deeply embedded into Canonical's Ubuntu and therefore should not be uninstalled from Ubuntu. But I uninstalled it anyway according to https://haydenjames.io/remove-snap-ubuntu-22-04-lts/
du
$ du pub # number of blocks for all subdirectories, summary total at end $ du -a pub # all files, as well as subdirectories $ du -s pub # summary total only $ du -h pub # human-readable number of bytes $ du --exclude="*.txt" pub # shell pattern, not regexp $ du -d 1 pub # depth, 0 is same as -s $ du -a pub | sort -n -r | head -n 20 # find largest files
Mount
Use the mount command to attach (mount) file systems and removable devices such as USB flash drives at a particular mount point in the directory tree.
$ mount # with no parameters, list mounted filesystems $ mount /dev/sda1 /media/john # mount a partition device to a mount point $ sudo mount /dev/sdb1 /mnt/media $ unmount device_name $ unmount mount_point
device name vs mount point
Both exist in the directory tree.
device name is /dev/sda1, for example.
Mount point is a directory which you create. For example:
- /media/seagate
- /mnt/stick128
Mount External USB Drive at Boot
$ lsusb # list USB devices $ sudo blkid # list UUID of all block devices # add line to /etc/fstab: # UUID=4078159978158F32 /media/seagate ntfs auto,nosuid,nodev,nofail,x-gvfs-show 0 0 $ sudo mount -a # test the changes to /etc/fstab. Error can cause boot failure. $ sudo systemctl reboot
/dev/sda is a disk
/dev/sda1 is a partition on the disk
We mount partitions, not disks.
tar
$ tar -czvf name-of-archive.tar.gz /path/to/directory-or-file $ tar -xvzf name-of-archive.tar.gz