You are reading the article How To Automatically Delete Old Files From Trash On Linux updated in September 2023 on the website Cersearch.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How To Automatically Delete Old Files From Trash On Linux
It’s almost certain that at one point in your life you will delete the wrong file or directory. Or you will intentionally erase a file, only to realize later that you need it again. Most of you may be thinking, “Been there, done that!”
But there’s a better way to get rid of data you don’t need anymore. And it’s something that is implemented in Windows 10, some of the newer smartphones and maybe some desktop environments included in Linux distributions.
However, the adoption rate of this system is still very low, and most users are not really aware of how useful it can be. It’s understandable since it’s one of those features that you can’t appreciate until the day it saves you.Permanent Delete vs. Send to Trash/Recycle Bin
Long story short: both of these options suck. Permanently deleting a file presents the obvious problem mentioned earlier. What if you later realize that you need the data? There’s no easy way to get that back, especially on ext4 filesystems. (It’s somewhat easier to undelete on Windows’ NTFS filesystem.)
It’s true that on most days you’ll zap some files and never need them again. But on a sunny day you will feel like cleaning up your computer.The Problem with Sending Files to the Trash
Let’s say you’re convinced now, even if the scenario doesn’t apply to you. Your company has good backup mechanisms in place, right?
But from now on, let’s say you renounce the sin of pressing Shift + Delete. Everything goes to the virtual Trash bin (or Recycle Bin if you’re on Windows). Need a file back? You can restore it in seconds.
That’s great! But what about freeing up space on your hard drive or SSD? Files in the trash still take up the same amount of storage space. You can empty the trash and free up space at any time – this is true. You probably won’t ever need the files that have been sitting there for weeks. But what about the last files you sent to the trash ten minutes ago? There’s no way to easily restore them now.
The conclusion is that every file needs to get “old” before it can be thrown out. If it sits in the virtual trash bin for a few weeks, and you didn’t need to restore it in that time, chances are you won’t ever need it again. On Linux there’s an utility called autotrash that can automate the process of purging only the old files from the trash.Schedule autotrash to Automatically Run Every Time You Log in to Your Desktop
Open your favorite terminal emulator, and install autotrash with the following command:
Enter your user’s password at the prompt.
Type “y” and press ENTER when asked if you want to continue.
Go back to your terminal emulator and type the following command:
In the text editor that opens, paste the line below:
Press Ctrl + X to exit the nano editor, “y” to save the modified file, and Enter.
Optional: if you also want to log autotrash activity in the systemd journal (if available on your distribution), you can paste a different line in .xsessionrc (but remove the previous one first):
Entries in the systemd journal, regarding autotrash, would look like the following image.Conclusion
At this point you can always send files to the trash instead of permanently deleting them. autotrash will automatically free up space on your disks. And you will always have a thirty-day window of opportunity to easily recover deleted data. You will certainly thank yourself one day for implementing this simple system.
Fell in love with computers when he was four years old. 27 years later, the passion is still burning, fueling constant learning. Spends most of his time in terminal windows and SSH sessions, managing Linux desktops and servers.
Subscribe to our newsletter!
Our latest tutorials delivered straight to your inbox
Sign up for all newsletters.
You're reading How To Automatically Delete Old Files From Trash On Linux
Update the detailed information about How To Automatically Delete Old Files From Trash On Linux on the Cersearch.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!