moving file

Hello ALL, i hope everyone is fine here.

I have found some directories that have 777 permission with below command.

find ./ -type d -perm 0777

e/uploads/
e/uploads/s1
j/uploads/
j/uploads/s1

I want that if there is any php|html|css file found in above directory so move those files to

/garbage/yyyy-mm-dd/ [move files to /garbage/2011-11-04/] . I want to run this script on every minute, during

moving files log file create for every move on same date directory. Please guide me.


while true
do
        sleep 60

        DATE=$(date +%Y-%m-%d)

        # Creates dir only if it doesn't already exist
        mkdir -p /garbage/${DATE}/

        find ./ '(' -name '*.php' -o -name '*.css' -o -name '*.html' ')' -exec mv '{}' /garbage/${DATE}/ ';' -print > /tmp/$$

        if [ -s /tmp/$$ ]
        then
                echo "Files moved on $(date)"
                cat /tmp/$$
        fi >> /path/to/logfile

        rm -f /tmp/$$
done
1 Like

if filename is already exist with same name so it will do, move new file with like

if abcd.txt exist then new file also exist is abcd.txt so it will move like that abcd.txt.1

is it possible?

What have you tried?

It is overwriting the file, lets say in garbage directory abcd.txt already exist, so it will move new abcd.txt that have 777 permission with name abcd.txt.1