Is a command available to free space of deleted file

Ken D'Ambrosio ken at jots.org
Tue Mar 30 15:33:04 UTC 2021


On 2021-03-30 10:14, Robert Heller wrote:
> At Tue, 30 Mar 2021 22:03:26 +0800 "Ubuntu user technical support, not
> for general discussions" <ubuntu-users at lists.ubuntu.com> wrote:
> 
>> 
>> On 30/03/2021, Bret Busby <bret.busby at gmail.com> wrote:
>> > Hello.
>> >
>> > I am using UbuntuMATE 20.10 .
>> >
>> > Is a command available, to free the space clogged up by a deleted file?
>> >
>> > .xsession-errorts
>> 
>> That should have been .xsession-errors .
>> 
>> > decided to eat my home partition free space, and
>> > grew to 32GB, so, I deleted it in the PCManFM file manager, using
>> > <SHIFT><DEL> .
>> >
>> > But, it clearly did not delete the file, as, while the file
>> > "officially" no longer exists, the partition is still full, with no
>> > free space, and, I need to free the space that the file still
>> > occupies, even after being deleted.
> 
> Once the fill is closed the disk space will be freed up.  Something 
> still have
> the file open, most likely the X server.  You will have to "exit" the X 
> server
> to free up the disk space.  In other words, you need to log out of your 
> X
> session.

Thanks to the wonder of /proc, so long as the file has not yet been 
reaped, you can both still see its contents, AND truncate it to reclaim 
its space, all without having to terminate tasks, etc.  So, for example, 
I have a file "date.txt" that I just deleted while it's still open for 
writing.  First, I'm going to use "lsof" to get the associated PID, 
which is the second column of the listing:

ken at hobbiton /tmp/modset $ lsof | grep date.txt
cat       50963                              ken    1w      REG          
      0,31        32    1379618 /tmp/date.txt (deleted)

Then I'm going to "cd" to the appropriate PID in /proc

ken at hobbiton /tmp/modset $ cd /proc/50963

Next, I'm going to cd to the "fd" -- file descriptor -- directory:

ken at hobbiton /proc/50963 $ cd fd

In there, there are three files.  "1" is the one we care about, which 
can be discerned from the "1w" (filehandle one, open for writing) in the 
lsof output:

ken at hobbiton /proc/50963/fd $ ls
0  1  2

And now, I can still cat it:

ken at hobbiton /proc/50963/fd $ cat 1
Tue 30 Mar 2021 11:27:17 AM EDT

And truncate it:

ken at hobbiton /proc/50963/fd $ > 1
ken at hobbiton /proc/50963/fd $ cat 1
ken at hobbiton /proc/50963/fd $

The filehandle is still technically open, but it's effectively no longer 
using any resources other than the filehandle, itself.

$.02,

-Ken






More information about the ubuntu-users mailing list