help required in program

I have below code, i need to modify it, to search for files (*.php,*.css,*.html) in those directores which have 777 permission, how to modify this code. Because it is moving all files.

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

I am searching on directories base. search for those directories which have 777 permission then search is there any php, css, html script exist or not.

---------- Post updated at 10:00 AM ---------- Previous update was at 09:42 AM ----------

i have total 4 directories which are 777 permission, if i will use above code, so i will specifiy and run this code time, while i want to modify the script in such a way it will get first 777 directories first and search in that directory is there any php,html,css exist then move it. I am not understanding that part to add directory checking which have 777 permission.

Try this...

find . -perm 777 -type d | find . -name "*.php" -exec ...

The first command will find you the directories with permission 777 and then you can search those directories for what you want and do whatever you want with them...

HTH
--ahamed

 find ./ -type d -perm 0777 

i want to add above code so it will search first 777 directories and then check php,css,html file respectively under 777 found directories. I hope everyone understand now.

That is what I have given... Check my post... Pipe it to your command...

--ahamed

ahmed bahi, i am using below code, but it is showing me all php,html. while it will show only two file.

find . -perm 777 -type d |  find ./ '(' -name '*.php' -o -name '*.css' -o -name '*.html' ')' 

If you want only php html etc files with 777 permission, then you need to add -perm 0777 in the second find command also... The first 7777 is for directories only...

--ahamed

those directories which are 777 permission dont have 777 permission files, but exist some one php, html file so i need to first search 777 directories that is working fine, in that directories i need to search php,html file whatever permission it have.

I am confused...
You want to search for directories which have 777 permission and in that you need to get all the files???
Or
You want to search for directories which have 777 permission and in that you need to get files with 777 permission???
What is it that you want?

--ahamed

Dear brother , i am sorry.

i am explaining again.

  1. first i want to search all 777 directories.
  2. when 777 directories found in those directories search php,html,css file whatever permission these files have no matter.
  3. move to /garbage directory

Got it... Try this...

find . -perm 777 -type d -exec find {} -name "*.php" \;

of course, expand the code to accomodate your file types--ahamed

It is showing same filename two times. how can i remove that.

that is weird... I am not getting that...

Please see below the command and its output.

[root@abcd xyz]# find . -perm 777 -type d -exec find {} -name "*.php" \;
./u24/sdfd/bash11.php
./u24/sdfd/bash11.php

See this... :D... I have given 777 permission to directory a and b...

root@bt:/tmp/test# find . -perm 777 -type d -exec find {} -name "*.c" \;
./a/aa.c
./a/a.c
./b/bb.c
./b/b.c

which is your OS?...

i have 777 permission to directory and 644 to file


[root@abcd xyz]# find . -perm 777 -type d -exec find {} -name "*.php" \;
./u24/sdfd/bash11.php
./u24/sdfd/bash11.php

[root@abcd xyz]# ls -l ./u24/sdfd/bash11.php

-rw-r--r-- 1 root root 0 Nov  6  2011 ./u24/sdfd/bash11.php

i am using fedora 15.

can you paste the output of

cd /u24/sdfd/
ls -lrt

--ahamed

here it is

# ls -ltr |more
total 106516

-rwxr-xr-x 1 root       root     60910 Oct 22 18:31 1278.jpg
-rwxr-xr-x 1 root       root     83672 Oct 22 18:31 12782115.jpg
-rwxr-xr-x 1 root       root     79711 Oct 22 18:31 1278220.jpg
-rw-r--r-- 1 root       root    167950 Oct 22 18:31 1291317.jpg
-rw-r--r-- 1 root       root     24878 Oct 22 18:31 1318434.jpg

Sorry pal... may be experts here can help you out... good luck...

--ahamed