Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Ubuntu Server 12.10 and I need to configure a cron job to delete some files in samba shares that belong to some criteria.

I'm configured some samba shares in /media/raid/. The folders are: process library users local

All these folders are specific samba shares with specific permissions. All of these folders have a sub-folder named .recycle that is used to store all deleted files in the shares.

What I need to do is to delete all files that are inside that shares (folders), in order to them go to the .recycle folder after they will be deleted, but I don't want to delete the files that have that same name in the .recycle folder.

The files are named '..rvt' where the first * is the file name and the second one is some numbers that auto increment, so that's the mask I need to use.

I have tried find command in multiple ways, but I always get the files inside .recycle folder.

I also need to assure that the files are removed like a user delete them, so they go to the .recycle directory.

Can you help???...

share|improve this question

Hard to do it in a single find, but quite easy if you split the task into something like this:

# Generate a list of paths
find <path> -iname "*.rvt" > potential_deletes.txt
# Discard files you don't want to delete
grep -v ".recycle" potential_deletes.txt > final_deletes.txt
# Perform deletion
rm `paste -s -d" " final_deletes.txt`
# Clean up
rm potential_deletes.txt final_deletes.txt

Of course, you could join all commands in a single line and avoid the creation of intermediate files.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.