Hard

Commands to check hard disk partitions and disk space on Linux

http://www.binarytides.com/linux-command-check-disk-partitions/

df

Df is not a partitioning utility, but prints out details about only mounted file systems.

The list generated by df even includes file systems that are not real disk partitions.

Here is a simple example

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda6        97G   43G   49G  48% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            3.9G  8.0K  3.9G   1% /dev
tmpfs           799M  1.7M  797M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            3.9G   12M  3.9G   1% /run/shm
none            100M   20K  100M   1% /run/user
/dev/sda8       196G  154G   33G  83% /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
/dev/sda5        98G   37G   62G  38% /media/4668484A68483B47

Only the file systems that start with a /dev are actual devices or partitions.

Use grep to filter out real hard disk partitions/file systems.

$ df -h | grep ^/dev
/dev/sda6        97G   43G   49G  48% /
/dev/sda8       196G  154G   33G  83% /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
/dev/sda5        98G   37G   62G  38% /media/4668484A68483B47

To display only real disk partitions along with partition type, use df like this

$ df -h --output=source,fstype,size,used,avail,pcent,target -x tmpfs -x devtmpfs
Filesystem     Type     Size  Used Avail Use% Mounted on
/dev/sda6      ext4      97G   43G   49G  48% /
/dev/sda8      ext4     196G  154G   33G  83% /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
/dev/sda5      fuseblk   98G   37G   62G  38% /media/4668484A68483B47

Note that df shows only the mounted file systems or partitions and not all.

lsblk

Lists out all the storage blocks, which includes disk partitions and optical drives.

Details include the total size of the partition/block and the mount point if any.

Does not report the used/free disk space on the partitions.

$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 465.8G  0 disk
├─sda1   8:1    0    70G  0 part
├─sda2   8:2    0     1K  0 part
├─sda5   8:5    0  97.7G  0 part /media/4668484A68483B47
├─sda6   8:6    0  97.7G  0 part /
├─sda7   8:7    0   1.9G  0 part [SWAP]
└─sda8   8:8    0 198.5G  0 part /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
sdb      8:16   1   3.8G  0 disk
└─sdb1   8:17   1   3.8G  0 part
sr0     11:0    1  1024M  0 rom

If there is no MOUNTPOINT, then it means that the file system is not yet mounted.

For cd/dvd this means that there is no disk.

Lsblk is capbale of displaying more information about each device like the label and model.

blkid

Prints the block device (partitions and storage media) attributes like uuid and file system type. Does not report the space on the partitions.

$ sudo blkid
/dev/sda1: UUID="5E38BE8B38BE6227" TYPE="ntfs"
/dev/sda5: UUID="4668484A68483B47" TYPE="ntfs"
/dev/sda6: UUID="6fa5a72a-ba26-4588-a103-74bb6b33a763" TYPE="ext4"
/dev/sda7: UUID="94443023-34a1-4428-8f65-2fb02e571dae" TYPE="swap"
/dev/sda8: UUID="13f35f59-f023-4d98-b06f-9dfaebefd6c1" TYPE="ext4"
/dev/sdb1: UUID="08D1-8024" TYPE="vfat"

How to check Swap space in Linux

This will show your allocated swap disk or disks, if any:

swapon -s

Type the following command to see total and used swap size:

cat /proc/swaps

This will show both your memory and your swap usage:

# Size options are: -k, -m, -g
$ free -m

Create iso image for swap

https://www.digitalocean.com/community/tutorials/how-to-configure-virtual-memory-swap-file-on-a-vps

$ cd /var
$ touch swap.img
$ chmod 600 swap.img

# to crate 512MB image file
$ dd if=/dev/zero of=/var/swap.img bs=1024k count=512
$ mkswap /var/swap.img
$ swapon /var/swap.img

Mount and UnMount usb

$ ls -la /dev/disk/by-uuid/
$ mkdir /mnt/sdc1
$ mount /dev/sdc1  /mnt/sdc1
# to unmount
$ umount /dev/sdc1

Summarize disk usage of each FILE, recursively for directories

-h, --human-readable
 print sizes in human readable format (e.g., 1K 234M 2G)
-s, --summarize
 display only a total for each argument
$ du -sh /home/or
12G     /home/or

$ ncdu /home/or

Clean NTFS partition for windows cache files

[email protected]:/home/or# mount -a

The disk contains an unclean file system (0, 0).

Metadata kept in Windows cache, refused to mount.

Failed to mount ‘/dev/sdb6’: Operation not permitted

The NTFS partition is in an unsafe state. Please resume and shutdown

Windows fully (no hibernation or fast restarting), or mount the volume

# sudo apt-get install ntfsprogs

# sudo ntfsfix /dev/sda3

ntfsfix is a utility that fixes some common NTFS problems. ntfsfix is NOT a Linux version of chkdsk.

It only repairs some fundamental NTFS inconsistencies,

resets the NTFS journal file and schedules an NTFS consistency check for the first boot into Windows.

You may run ntfsfix on an NTFS volume if you think it was damaged by Windows or some other way and it cannot be mounted.

Make sub directory

$ mkdir -p /new/sub/folder

How to Sort Folders by Size With One Command Line in Linux

$ du --max-depth=1 /home/ | sort -n -r
$ du -H --max-depth=1 /home/user
$ du -h --max-depth=1 | sort -hr

http://www.ducea.com/2006/05/14/tip-how-to-sort-folders-by-size-with-one-command-line-in-linux/

http://unix.stackexchange.com/questions/185764/how-do-i-get-the-size-of-a-directory-on-the-command-line

How to Free Up a Lot of Disk Space by Deleting Cached Package Files

$ sudo du -h /var/cache/apt/archives
$ sudo apt-get clean

Disable Automatic Package Caching

If you’d rather not have to go in and clean out the cache folders all the time, you can tell Ubuntu to stop keeping them around with a simple configuration change. Head into System –> Administration –> Synaptic Package Manager. Then choose Settings –> Preferences Switch over to the Files tab, where you can change the option to “Delete downloaded packages after installation”, which will prevent the caching entirely.

Mount unknown filesystem exfat

$ sudo apt-get install exfat-fuse exfat-utils