Black Friday 2025 – NPI EA (cat = Baeldung on Linux)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

Baeldung Pro – Linux – NPI EA (cat = Baeldung on Linux)
announcement - icon

Learn through the super-clean Baeldung Pro experience:

>> Membership and Baeldung Pro.

No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.

Partner – Orkes – NPI EA (tag=Kubernetes)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

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.