Sobes.tech
Junior — Middle

Why can a file write command fail even if 'df -h' shows free space?

sobes.tech AI

Answer from AI

A command to write a file may fail despite df -h showing free space, for several reasons:

  1. User quotas — even if there is free space on the disk, the user may have a quota limit, and cannot write more data.

  2. Reserved space for root — in filesystems like ext4, about 5% of space is usually reserved for system needs and the root user. Regular users cannot use this space, so df will show it as free, but writing will fail.

  3. Inode limitations — the number of available inodes (structures for storing file information) on the disk may run out, preventing new files from being created despite available space.

  4. Access rights and locks — the file may be locked or the user may not have write permissions.

  5. The filesystem is mounted in read-only mode — then writing is impossible.

Example of checking inodes:

df -i

Thus, free space according to df is not the only factor affecting the success of writing a file.