One of the things I'm obsessed about during the last year is reducing the number of things that I have.
For example, the laptop where I'm typing now has 128 GB SSD—it's 8 years old and storage is more than scarce. When the amount of space decreases drastically, instead of thinking of buying an external SSD or a new laptop, why not reducing the files on it?
Last year I created a folder to put old files on there. Files that aren't being opened for year, get deleted.
Here is the script:
#!/bin/bash # Vacuum cleaner # It deletes old files of a folder # # Copyright © 2020 Erik Martín Jordán # All rights reserved # Declaring root of files quarantine quarantine_folder=~/Desktop/Quarantine/* # Period to quarantine the files one_year=$((365 * 24 * 60 * 60)) # Current date in epoch current_date=$(date +%s) # Iterating through quarantine folder for file in $quarantine_folder do # Geetting name and last access of file name=$(basename "$file") last_access=$(stat -f %a "$file") # Diffrence between current date and last access difference=$((current_date - last_access)) # Remove file if difference is > 1 year if [ "$difference" -gt "$one_year" ] then $(rm "$file") fi done
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.