Bash script / Cron job to move files from one folder to another

spiros · 1 · 2948

spiros

  • Administrator
  • Hero Member
  • *****
    • Posts: 824385
    • Gender:Male
  • point d’amour
Bash script / Cron job to move files from one folder to another

Code: [Select]
#!/bin/bash

sold="/home/mysite/public_html/folder/path_1"
snew="/home/mysite/public_html/folder/path_2"

find $sold -type f -maxdepth 1 -name "*.htm*" -mtime +1 -exec mv {} $snew \;

The -name "*.htm*" bit defines the type of files (in this case only html and htm extensions)
The -mtime +1 moves files that are one day old.

You can omit/edit any of these parameters.
Of course, you will need to edit the sample paths listed on top of the script.

Make sure when you edit your file that you have Unix line endings. Some text editors like Notepad++ let you see and change this. Give it an .sh extension.

To set up the cron job see:
Bash script to automatically back-up and compress a MySQL database and delete older backups in Linux servers
« Last Edit: 09 Nov, 2020, 08:57:17 by spiros »


 

Search Tools