SSH Command in Linux with examples

Disk and storage commands in Linux

Check free space, find what is using it, and work with disks and mounts.

Watch: Linux Disk Full? Find What's Using Space (df, du, find)

Read the video transcript

A full disk is one of the most common ways a Linux server fails. In this video, you'll learn how to check free space, find out what is using it, and track down the biggest files. All live, on a real Ubuntu server, with SSH Command. We're connected to the server, with the Shell view open. I've put a few large demo files in a folder called disk-demo, so there is something to find. Start with df, which stands for disk free. It lists every filesystem and how full it is. The dash h option means human readable, so you see gigabytes instead of raw blocks. Ignore the temporary lines, and look for the filesystem mounted on slash. That's the main disk. Give df a path, and it shows only that one. This disk is ten gigabytes, with five point four used, and four free. That's fifty-eight percent. When Use percent passes ninety, it's time to act. A disk can also run out of inodes, which count files, not bytes. df dash i shows them. Here, only twenty-eight percent are used. df tells you the disk is filling up. du tells you what is filling it. du dash s h prints the total size of a folder: s for summary, h for human readable. Add a star to see each item inside the folder separately. Then pipe it into sort dash r h, which ranks the sizes from largest to smallest. Media is the biggest, then backups, then logs. To find individual big files, use find with dash size. Here we look for regular files over one hundred megabytes. Two files turn up. ls dash l h S sorts a folder by size, largest first. The holiday video is four hundred and fifty megabytes. lsblk shows the disks themselves. Dash e seven hides the loop devices that snap packages create. Our virtual disk, vda, is ten gigabytes, and the root partition takes nearly all of it. SSH Command shows the same information in the Files view. Sizes sit right in the listing, so the big files stand out, and you can select a file and remove it with one click. Once you have found the culprit, free the space. rm removes the file. There is no undo, so be sure. Run df again, and the free space has grown by about four hundred and fifty megabytes. That's how to check disk space on Linux: df for the big picture, du to see what is using it, and find to track down large files. The full guide is at ssh command dot com, under disk commands. SSH Command is free for personal use. The link is in the description. Thanks for watching.

#df

Free disk space

Syntaxdf [options]
  • df -h

    Space per disk in human-readable sizes

  • df -hT /

    One filesystem including its type

  • df -i

    Inode usage (a disk can be "full" of tiny files)

#du

Space used by folders

Syntaxdu [options] path
  • sudo du -sh /var/log

    Total size of a folder

  • sudo du -h --max-depth=1 /var 2>/dev/null

    Size of each sub-folder (2>/dev/null hides the errors for folders you cannot open)

  • du -ah . | sort -rh | head -20

    The twenty biggest items under here

#lsblk

List disks and partitions

Syntaxlsblk
  • lsblk

    Tree of disks and where they are mounted

  • lsblk -f

    Add file system type and labels

#blkid

Show disk IDs

Syntaxsudo blkid
  • sudo blkid

    UUID and type of every partition

#mount

Attach a disk

Syntaxsudo mount device folder
  • mount

    List what is mounted

  • sudo mount /dev/sdb1 /mnt/data

    Mount a partition

  • sudo mount -o ro /dev/sdb1 /mnt/data

    Mount it read-only

#umount

Detach a disk

Syntaxsudo umount folder
  • sudo umount /mnt/data

    Safely unmount

#fdisk

Partition a disk

Syntaxsudo fdisk [-l] device
  • sudo fdisk -l

    List all disks and partitions

CarefulPartitioning and formatting destroy data. Double-check the device name (for example /dev/sdb) before you press Enter.

#mkfs

Format a partition

Syntaxsudo mkfs.type device
  • sudo mkfs.ext4 /dev/sdb1

    Create an ext4 file system (erases the partition)

#fsck

Check a file system

Syntaxsudo fsck device
  • sudo fsck /dev/sdb1

    Check and repair (the disk must be unmounted)

#free

Memory use

Syntaxfree [-h]
  • free -h

    RAM and swap in human-readable sizes

Run these commands with SSH Command

SSH Command is a desktop app for Mac, Windows and Linux that puts a real terminal, SFTP file panes, a sudo switch and a searchable Linux command finder in one window. Type what you want to do, and send the command to your server with one click.

Download free Windows commands with examples SFTP & FTP client