When a borrowed or loaned computer goes back to its owner, your files, saved passwords and traces should leave with you, and none of the owner’s should be touched. On Linux, deleting is less final than it looks. rm removes a file’s name but not its contents, the shell saves your commands when you log out, and a log file that’s still open survives being deleted. This page covers the traps that matter and the habit that beats each one.

I learned these cleaning a robot’s onboard computer at work before it went back to its owner, and then wrote the steps into a script so the next cleanup goes the same way.

What rm does, and what it doesn’t

File on diskAfter rmAfter fstrim config.yaml points to data blocks rm name gone data still readable fstrim name gone drive discards the blocks

A file is a name that points to blocks of data. rm deletes the name and marks the blocks as free, but their contents stay until something else overwrites them, and recovery tools can read them back until then. On an SSD, fstrim tells the drive which blocks are free, and the drive discards them.

Make the freed space unrecoverable

sudo fstrim -v /

It prints how much it trimmed. The number covers only space freed since the last trim, and Ubuntu runs a trim once a week by default, so it’s usually much smaller than the drive’s free space. If the drive reports that discard isn’t supported, fill the free space with zeros using dd into a temporary file until the disk is full, then delete that file. Expect “No space left on device” at the end, and expect it to take a long time on a large drive.

Trimming makes recovery with ordinary tools impractical on most SSDs, but it isn’t a certified erase. If an agreement requires data to be destroyed, reinstall the machine from the vendor’s image or use the drive’s own secure-erase function.

Don’t leave your own trail

TrapWhy it happensHabit
Your cleanup commands end up in the owner’s shell historyBash keeps the session’s commands in memory and writes them to ~/.bash_history when you exitRun unset HISTFILE at the start of the session. It only affects the current shell, so repeat it after reconnecting.
A pasted command is typed in as a passwordWhen sudo asks for a password halfway through a pasted block, the next pasted line becomes the passwordRun sudo -v first. It asks once and keeps sudo unlocked for a few minutes (15 by default on Ubuntu).
A deleted log file still takes up spaceA program that has the file open keeps writing to it, and the data stays on disk until the program closes itEmpty it in place with truncate -s 0. For the system journal, run journalctl --rotate, then journalctl --vacuum-time=1s.
Your editor remembers your files~/.viminfo records recently opened files and searchesDelete it, or remove the lines that mention your work
Saved Wi-Fi passwords stay behindNetworkManager stores every network’s password, readable with sudoDelete your networks with nmcli connection delete

Sort before you delete

Search the disk for your names, then put every hit in one of three groups before deleting anything: yours, the owner’s, or the operating system’s. A search word can match system files that happen to share the name. dpkg -S <path> tells you which package installed a file, so you can see whether it’s yours. Ask the owner about anything you can’t place.

After deleting, search the whole disk again. A second search usually finds something the first pass missed, such as a package manager’s cached catalogue or a container engine’s leftover records.

Check a backup before deleting the original

If something might be needed again, archive it, then prove the archive is complete before deleting:

tar -czf backup.tar.gz -C ~ project
gzip -t backup.tar.gz && echo ARCHIVE OK
sha256sum backup.tar.gz

gzip -t reads the whole archive and fails if it’s cut short. Copy it to the other machine, run the same two checks there, and delete the original only when both say ARCHIVE OK and the two checksums match exactly. An archive interrupted mid-write looks normal until the day you need it.

After a trim, deleted files are gone for good

Up to the fstrim, a file deleted by mistake can sometimes be recovered. After it, the drive has discarded the data. Finish sorting, check backups, and search again before you trim.