Most Linux server emergencies start with the disk: a full filesystem stops databases and mail, a filesystem error after a crash stops the server booting, and wrong permissions break websites or open them to attack. This guide covers the commands you need to watch disk space, find what is using it, check and repair filesystems, add a new disk, and set ownership and permissions correctly.
Use df -hT and df -i to see space and inodes, and du or ncdu to find what is filling the disk. Check a filesystem only when it is unmounted: e2fsck for ext4, xfs_repair for XFS, with a dry run first. Mount new disks by UUID in /etc/fstab and test with findmnt --verify before you reboot. For websites, directories are usually 755 and files 644; never use 777.
Everything here is for a VPS or server where you have root access. On shared hosting you can't partition disks or run filesystem checks; section 8 covers what you can do there instead.
1. See how much space is left
df -hT # size, used, free and type of every mounted filesystem
df -i # inodes: the number of files a filesystem can still hold
findmnt # what is mounted where, as a treeA filesystem can report "No space left on device" while df -h still shows free space. That means it has run out of inodes, usually because of millions of tiny files such as PHP sessions, cache fragments or mail in a queue. df -i shows it straight away.
2. Find what is using the space
sudo du -xh --max-depth=1 / | sort -h # biggest top-level folders, this filesystem only
sudo du -xh --max-depth=1 /var | sort -h # then drill down
sudo find / -xdev -type f -size +500M -exec ls -lh {} \; # single large filesncdu (install it from your distribution's packages) does the same interactively and lets you delete as you go. The usual suspects on a web server:
| Location | What fills it | Safe fix |
|---|---|---|
| /var/log | Old or runaway logs | Fix the noisy service, then sudo journalctl --vacuum-size=500M and logrotate |
| /var/lib/mysql | Databases, binary logs | Purge old binary logs from MySQL; never delete data files by hand |
| /var/lib/docker | Old images and containers | docker system prune after checking what it will remove |
| /home or /var/www | Backups left in the web root | Move them off the server |
| /tmp | Abandoned uploads and sessions | Remove files older than a few days |
If df still shows the disk full after you deleted a big file, a running process is holding it open. sudo lsof +L1 lists deleted-but-open files; restart that service to free the space.
3. List disks and partitions
lsblk -f # disks, partitions, filesystem type, label, UUID and mount point
sudo blkid # UUIDs and types, for /etc/fstabOn a KVM VPS the disk is usually vda (partitions vda1, vda2); on other systems it may be sda or nvme0n1. Read the output carefully before you run anything that writes to a device.
4. Check and repair a filesystem
Running a repair on a mounted filesystem can destroy data. Unmount it first. The root filesystem can only be checked at boot or from a rescue system. Take a backup of anything you can still read before you repair.
ext4. Do a read-only check first, then repair:
sudo umount /data
sudo e2fsck -fn /dev/vdb1 # -n: report only, change nothing
sudo e2fsck -fy /dev/vdb1 # -y: fix, answering yes to every questionXFS (the default on AlmaLinux and Rocky Linux) uses its own tool; fsck does nothing on XFS:
sudo umount /data
sudo xfs_repair -n /dev/vdb1 # dry run
sudo xfs_repair /dev/vdb1 # repairIf xfs_repair refuses because of a dirty log, mount and unmount the filesystem once to replay the log. xfs_repair -L throws the log away and can lose recent changes: use it only as a last resort.
The root filesystem. On systemd distributions, add fsck.mode=force to the kernel command line for one boot, or check from a rescue system. Most distributions also check the root filesystem automatically at boot after an unclean shutdown.
5. Add a new disk or partition
- Create a partition table and partition.
sudo parted /dev/vdb --script mklabel gpt mkpart data 0% 100%(or usefdiskinteractively). - Make the filesystem.
sudo mkfs.ext4 /dev/vdb1orsudo mkfs.xfs /dev/vdb1. - Mount it.
sudo mkdir -p /data && sudo mount /dev/vdb1 /data - Add it to /etc/fstab by UUID.Get the UUID with
blkid, then add a line likeUUID=your-uuid /data ext4 defaults,nofail 0 2.nofaillets the server boot even if this disk is missing. - Test before rebooting.
sudo findmnt --verifyandsudo mount -a. An fstab mistake can stop the server booting.
On a VPS, extra space usually comes from moving to a bigger plan, which grows the existing disk. You then grow the partition and filesystem instead of creating a new one; Cloning and resizing your VPS shows how with growpart, resize2fs and xfs_growfs.
6. Ownership and permissions
Every file has an owner, a group, and permissions for the owner (u), the group (g) and everyone else (o).
| Number | Meaning | Typical use |
|---|---|---|
| 755 | Owner all; group and others read and enter | Directories, scripts |
| 644 | Owner read and write; others read | Web files, images, HTML, PHP |
| 600 | Owner only, read and write | Config files with passwords, SSH keys |
| 700 | Owner only, everything | Private scripts and folders, ~/.ssh |
sudo chown -R www-data:www-data /var/www/example # owner:group (nginx/apache user varies by distribution)
chmod 640 wp-config.php # numeric
chmod u+x deploy.sh # symbolic: add execute for the owner
find /var/www/example -type d -exec chmod 755 {} + # directories
find /var/www/example -type f -exec chmod 644 {} + # filesAvoid chmod -R 755 on a whole site: it makes every file executable. Use the two find commands instead. And never use 777; it lets any process on the server change your files, which is how many hacked sites get infected.
7. Keep the disk healthy
- Set up log rotation for every application log you create.
- Alert yourself when a filesystem passes about 80% full, before it becomes an outage.
- Keep backups off the server, not in the web root or on the same disk.
- After a crash or forced restart, read
journalctl -b -p errfor filesystem errors.
8. On shared hosting
On shared hosting (cPanel, DirectAdmin, Webuzo) the server's disks are managed for you. You can still:
- see your disk and inode usage in the control panel; see how to check disk and bandwidth usage;
- change permissions in the File Manager; see how to use the File Manager, and for DirectAdmin, where home folders are 710,
domainsis 711 andpublic_htmlis 755, managing file permissions in DirectAdmin; - use
du,find,chmodandlsover SSH. Jailed SSH access is available on every shared hosting plan; it is off by default, so ask support to enable it for your account. Logins use an SSH key. See enabling jailed SSH.
9. Where Domain India fits
A Domain India VPS gives you the root access these commands need, on KVM with NVMe storage. It is self-managed, so disk health and backups are yours to look after, and support helps with anything outside the server, such as a forced restart. Live price, excluding 18% GST:
- 1 vCPU
- 2 GB DDR4 RAM
- 64 GB NVMe SSD Storage
- 2 TB Monthly Bandwidth
How do I check disk space on a Linux server?
Run df -hT to see the size, used space, free space and type of each mounted filesystem, and df -i to see inode usage. Use du or ncdu to find which folders are using the space.
Why does Linux say no space left when df shows free space?
The filesystem has run out of inodes, the entries that record each file. Run df -i to confirm, then find and remove the folder holding millions of small files, such as old sessions or cache files.
Can I run fsck on a mounted filesystem?
No. Checking or repairing a mounted filesystem can destroy data. Unmount it first, or check the root filesystem at boot or from a rescue system.
How do I check an XFS filesystem?
Unmount it, run xfs_repair -n for a read-only check, then xfs_repair to fix it. The fsck command does not repair XFS.
What permissions should website files have?
Usually 755 for directories and 644 for files, with 600 or 640 for configuration files that hold passwords. Never use 777.
Can I run these commands on shared hosting?
Partitioning and filesystem checks need root access, so they only work on a VPS or your own server. On shared hosting you can check disk usage in the control panel and change permissions in the File Manager or over jailed SSH, which support enables on request.
Ready to manage your own server? Read the Linux shell commands guide, compare VPS plans, or open a ticket if a disk problem on your server needs our help.
KVM VPS plans with full root access, NVMe storage and a choice of Linux operating system.
See VPS plans