LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Delete regular files (not hidden files) with find + rm in one line older than 15 (http://www.linuxquestions.org/questions/linux-newbie-8/delete-regular-files-not-hidden-files-with-find-rm-in-one-line-older-than-15-a-855070/)

Virtuose 01-08-2011 05:16 PM

Delete regular files (not hidden files) with find + rm in one line older than 15
 
Hi Everybody..

I have the following issue:

We at our company have some FTP users who upload files to our Debian linux 9.x version server. This server represents our company web page (1 one them). There are several ftp users who can upload (with fpt client) to their home directory (each user home directory is their root directory so they cannot go a level higher up to /home) Now company policy says that any file uploaded older than 15 days must be deleted from each of their home directory. We have the vsftpd deamon running and we have a banner that warns the user about this in the conf file.
I found on this forum some interesting code but need some help.

My code would be: (in a bash script)

find /home * -type f -mtime +15 -exec rm {} \;

(maybe -name should be added or other option)

Result: delete files older than 15 days in /home and subfolders (really there will be nothing stored in the /home directly, only in users ftp directories there will be uploaded stuff).
PROBLEM: this command will also delete the hidden dot files files, like profile files, .bash_profile etc... How can i prevent that these hidden dot files are not delete from each user ftp directory under the /home directory. Please help to correct my code. The * in find command sign will wipe everyting !!! Thanks in advance

Tinkster 01-08-2011 05:24 PM

Hi, welcome to LQ!

And yes, the '*' is a plain old big fat mistake. It will add
any directory or file in the current working directory to finds
search list.

To exclude files/dirs that start with a '.' you want to do
Code:

find /home -type f -mtime +15 -not -name ".*" -exec rm {} \;
For a test run I'd recommend using an "echo" between the exec and the rm ;}



Cheers,
Tink


All times are GMT -5. The time now is 02:46 AM.