I'm trying to write a janitor script that will run as a cron job in one specific directory. It is supposed to create an archive folder with the date of creation in the name, and then find and move all files of a certain type into this new folder.Here is my test code:#!/bin/bashtoday=$(date +'%m:%d:%Y')target=Archived-$todaymkdir -p $targetfind . -type f -name *.zip -exec mv -i {} /$target \;It manages to create the folder correctly, but is unable to move the files it finds into the folder. I have only been doing this as a small test, and both the script and the files have been created by the same user. If I add sudo to the beginning it tries to move the files, but instead what happens is that it only deletes the files from the current directory, but does not place them in the newly created directory. I am not trying to move .zip files. Just an example. I have tried by having chmod 777 on both files and folders. Same thing happens. I am running ubuntu 14.04 LTS.If there is a much better way to do this, please tell me. Any pointers in the right direction would be very much appreciated.EditNow it works.I updated the find statement to:find . -maxdepth 1 -type f -name *.zip -exec mv -t $target/ {} \;
Bash script unable to move files
bash;permissions;scripting;find;mv
find files in current dir not subdirs :find . -maxdepth 1  -type f -name '*.zip'  -exec mv -t $target/ {} \;exclude dirs methode :find . -type f -not -path $target/*  -name '*.zip'  -exec mv -t $target/ {} \;Note that this will exclude only today's archive while you'll have other archive , i recommand the first command , or creat archive-dirs outside the main dir !