Skip Navigation
ShareGPT @reddthat.com

create a temporary directory for my user in Linux to hold each file for 90 days since the last modification date

Here is a command to create a temporary directory for your user that will hold files for 90 days since their last modification date:

 bash
    
mkdir ~/tmp
chmod 700 ~/tmp

find ~/tmp -type f -mtime +90 -delete

  

This will:

  • Create a directory called ~/tmp owned by your user
  • Set permissions on it so only you have access
  • Run find daily to delete any files older than 90 days inside the ~/tmp directory

To automate the find command, you can add it to your crontab by running:

 
    
crontab -e

  

And adding:

 
    
0 0 * * * find ~/tmp -type f -mtime +90 -delete

  

This will run the find command every day at midnight to clean up files older than 90 days in ~/tmp.

The ~/tmp directory will now persist and hold files for 90 days since their last modification date before being automatically deleted.

0 comments

No comments