I'm sure you've already come across them already, but the two best places to begin with learning bash scripting are the Bash Guide for Beginners and the Advanced Bash-Scripting Guide. If you haven't seen these two resources yet, I would highly recommend bookmarking them if you're looking to do further bash scripting.
Removed portion regarding flow control due to edit in question. The find command needs -exec
before the command or else it won't know that mv
is actually a command you're attempting to execute on the files. Also, the {}
in the find is used to refer to the results of the find command, thus you won't need $source
as part of the find. The find command would probably look more like:
find $source -mtime +$days -exec mv {} $destination \;
If the find results will include files/directories with spaces in them, then you may need to loop through the results (which will bring the do/done back into the mix) so that you can include the results of the find in a variable that can then be enclosed in quotes. That will give a structure similar to the following:
for result in $(find $soure -mtime +$days)
do
mv "${result}" $destination
done
If you're still having problems, I'd suggest including a copy of your terminal window from running the script. Also, try running just the find command by itself without the -exec mv...
portions and replacing the variables with what you'd normally fill in for them during the script execution. That way you can get an idea as to what the find command is matching so you can be certain that it's matching the files you want it to before making any changes to the location of your files.
mv
is a command , not an argument .The way you have writtenmv
is taken as an argument offind
.You either need it to be passed through -exec argument or pipe (|
) the results from find tomv