Skip to content

How to safely remove large file in Linux

The File is Still Open

One of the reasons why disk space doesn’t change after removing large files is that the file is still open. If a file is open, it is still being used by a process, even if you have deleted it. The space used by the file is not freed until the process using the file is terminated or closed. To check if a file is open, you can use the lsof command followed by the filename. Once you have identified the process using the file, you can terminate it using the kill command.

Deleting unused files

NOT use

rm -f filename

If the file handle is open/writing, directly rm will not release the disk space. In this case, you can consider freeing up file space by redirecting.

Emptying in-use files

Recommended

cat /dev/null > filename
## or
: > filename
## or
> filename
## or
echo "" > filename
## or
echo > filename
Feedback