1. Overview
Often, we browse through files and directories on our computers and get rid of unused ones. In a Graphical User Interface (GUI), when we delete a file or directory, the system moves it to the recycle bin or trash. The system stores deleted directories or files temporarily there, and we can retrieve them later if needed.
However, on the Linux command line, we usually use the rm command to delete files and directories. In this short tutorial, we’ll learn where files go when issuing the rm command.
2. Where Do Files Go When We Run the rm Command?
Before we go into where the files go, let’s take a quick look at how the Linux filesystem works. When we create a file, the system creates a link to it. The system then uses these links to locate files on the disk.
When we issue the rm command, the system only deletes the link to the file. In other words, the file’s data itself remains on the disk. Hence, when we issue the rm command, the filesystem removes the reference to the files and notifies the system that the storage blocks have been freed.
Usually, running the rm command tells the system to label the inode and the data blocks of the file as unused.
In older Linux versions, it used to be possible to retrieve the data, but nowadays, the metadata is wiped, and nothing is recoverable.
The rm command doesn’t have a recycle bin or a trash can. If we need a recycle bin, we should use the GUI, where files are usually moved to the trash directory when deleted.
3. Conclusion
In this short article, we learned that when we issue the rm command, the filesystem removes the link to the files. To this end, the caveat is to ensure that before we issue the rm command on files, we should back up those files in another directory.
For server environments without a GUI, an alternative to using the rm command is to create a trash directory where we can move unwanted files. In that case, we’d use the mv command rather than rm.