Translation - Μετάφραση

Resources, Technical Assistance and Technology News => Tips on Using Computers => Translator resources => Linux tips => Topic started by: spiros on 30 Dec, 2014, 19:18:55

Title: Bash script / Cron job to move files from one folder to another
Post by: spiros on 30 Dec, 2014, 19:18:55
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++ (http://notepad-plus-plus.org/) 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 (https://www.translatum.gr/forum/index.php?topic=381856.0)