10

I want to make free space on my computer, and Baobab tells me /tmp is 8 Gio large. Can I delete all the files in /tmp safely? Do I have to close some programs first?

Additionally, why is this directory so big? Though my /etc/defautl/rcS indicates TMPTIME=0?

Agmenor
  • 16,434

1 Answers1

11

In Unix, deleting a file removes a reference to it from its parent directory (this actually is called "unlinking").

The actual file data is only deleted when it's not referenced from any directory (a file can have multiple so-called hardlinks) and it's not open by any program.

So yes, deleting files from /tmp should not crash programs which potentially keep those files open. On the other hand, the actual disk space won't be freed until the program closes the already-deleted file.

Sergey
  • 44,443
  • Nothing crashed on my computer after deletion, so I am glad to accept your answer! – Agmenor Aug 26 '11 at 04:07
  • But it's conceivable that a program (or more likely a script that invokes a sequence of commands) has to open and close the same file a few times. Such a program could fail when the file name is unlinked. – Alex Jasmin Aug 26 '11 at 13:45
  • 1
    @Alexandre Jasmin: such a program could fail but should managed the situation, if projected correctly (re-creating the file, or logging the error then exiting gracefully, if fatal, and so on). – enzotib Aug 26 '11 at 16:38
  • I am unable got get past lightdm after deleting the /tmp directory: sudo rm -rf /tmp – Juzer Ali Dec 05 '12 at 04:51
  • @ Juzer Ali - you should have removed the contents with sudo rm -rf /tmp/* (note the *) not the entire directory. To stop /tmp getting too large you can mount it as a tmpfs with a fixed size. – Stuart Cardall Dec 27 '17 at 09:32