LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 01-08-2011, 05:16 PM   #1
Virtuose
LQ Newbie
 
Registered: Jan 2011
Posts: 5

Rep: Reputation: 0
Question 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
 
Old 01-08-2011, 05:24 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
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
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I make find exclude hidden files (.files) Rotwang Linux - General 2 08-08-2011 03:58 AM
[SOLVED] How to delete multiple hidden files dbuehler Linux - Newbie 8 03-18-2010 07:09 AM
LXer: fdupes - Command line tool to find and list/delete duplicate files LXer Syndicated Linux News 0 10-28-2008 03:40 PM
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 03:43 PM
How to delete hidden files??? kabucek Linux - Distributions 5 08-27-2006 11:21 PM


All times are GMT -5. The time now is 06:27 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration