LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find (http://www.linuxquestions.org/questions/linux-newbie-8/find-881583/)

albicocca 05-19-2011 07:55 AM

find
 
Hi,

I've setup a samba share with RecycleBin option.
However, there is no cleanup and soon will saturate free space.

I'm trying to plan a command that each week clean the content of those dir or the directory itself.

The dir tree is like /home/ :
  • user1
    • Dir1
    • Dir2
    • RecycleBin
  • user2
    • Dir1
    • Dir2
    • RecycleBin
  • samba
    • groups
    • netlogon
    • profiles
    • shares
      • share1
        • Dir1
        • Dir2
        • RecycleBin
      • share1
        • Dir1
        • Dir2
        • RecycleBin
      • share3
        • Dir1
        • Dir2
        • RecycleBin

I think find is the easy way.
Further more I wish some of those dir are excluded: in the following example "mango" directory.

Code:

find . -name mango -prune -o -name 'RecycleBin' -type d -exec rm -rf {} \;
If works fine but I get an error message:

Code:

rickyx@Balenotterax:~/Scrivania/testrb$ find . -name mango -prune -o -name 'RecycleBin' -type d -exec rm -rf {} \;
find: "./user 3/RecycleBin": File o directory non esistente
find: "./user 2/RecycleBin": File o directory non esistente
find: "./user 1/RecycleBin": File o directory non esistente
rickyx@Balenotterax:~/Scrivania/testrb$

I can't figure out where I'm wrong.

To be careful to all possible situations I'm testing this line in directory with spaces in names. I know is ugly and ... and ... but users are just used to and they don't care about me ;) And, having this line working for spaces I can use it for other situations other than shares.

File o directory non esistente = File or directory does not exist

Thank you,
Ricky

gilead 05-19-2011 06:30 PM

I don't think you've done anything wrong - find is trying to report on the directory after it's been deleted and can't find it. If you're happy that the script is working properly now, you could just dump the error output by adding " 2>/dev/null" to the end of the command

albicocca 05-19-2011 06:37 PM

I' thought that pruning was wrong.
I'll test on the server itself and report the result.

Thank you,
Riccardo

crts 05-19-2011 08:25 PM

Hi,

you can avoid those error messages by using find's -delete option instead or the -depth option.
Simplified example:
Code:

find /some/path -depth -name 'some_name' -type d -exec rm -rf '{}' \;
# or
find /some/path -name 'some_name' -type d -delete



All times are GMT -5. The time now is 10:38 PM.