LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 08-24-2012, 10:06 PM   #1
caiphn
LQ Newbie
 
Registered: May 2012
Posts: 15

Rep: Reputation: Disabled
Question Directory exclusion using the 'find' command question


Hello!

I am currently have this in my crontab file to delete files that are older than 90 days:

find /opt/files/users/stopper/ -type f -mtime +90 -delete

I'd like to omit the logs directory, and all child directories of the logs directory which exists at this path: /opt/files/users/stopper/logs

I've looked through the manual for the find command but I'm not sure if there is anything I can use in order to omit the path and all its child folders from the deletion which is occurring. Any assistance or suggestions are appreciated, thank-you.
 
Old 08-24-2012, 10:10 PM   #2
KinnowGrower
Member
 
Registered: May 2008
Location: Toronto
Distribution: Centos && Debian
Posts: 347

Rep: Reputation: 34
click here to get help
 
1 members found this post helpful.
Old 08-24-2012, 10:10 PM   #3
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
Code:
find /opt/files/users/stopper/ -wholename /opt/files/users/stopper/logs -prune -o -type f -mtime +90 -delete

Last edited by byannoni; 08-24-2012 at 10:11 PM.
 
1 members found this post helpful.
Old 08-24-2012, 10:49 PM   #4
caiphn
LQ Newbie
 
Registered: May 2012
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by byannoni View Post
Code:
find /opt/files/users/stopper/ -wholename /opt/files/users/stopper/logs -prune -o -type f -mtime +90 -delete
Thank you for the quick response. What does -wholename do in this case, googling around wasn't helping. Also, what does the -o do? On the example page the KinnowGrower showed, it only was used when there was two paths to be excluded.

Last edited by caiphn; 08-24-2012 at 11:03 PM.
 
Old 08-24-2012, 11:44 PM   #5
caiphn
LQ Newbie
 
Registered: May 2012
Posts: 15

Original Poster
Rep: Reputation: Disabled
wholename pattern
File name matches shell pattern pattern. The metacharacters do
not treat `/' or `.' specially; so, for example,
find . -wholename './sr*sc'
will print an entry for a directory called './src/misc' (if one
exists). To ignore a whole directory tree, use -prune rather
than checking every file in the tree. For example, to skip the
directory `src/emacs' and all files and directories under it,
and print the names of the other files found, do something like
this:
find . -wholename './src/emacs' -prune -o -print


Thank-you!
 
Old 08-25-2012, 08:09 AM   #6
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
I just used wholename for pathes, since name only matches the base name. -o is the or operator. It might not be necessary in this case.
 
Old 08-25-2012, 08:13 AM   #7
caiphn
LQ Newbie
 
Registered: May 2012
Posts: 15

Original Poster
Rep: Reputation: Disabled
Again, thanks!
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can yum override an exclusion in the /etc/yum.conf directory eodchop Fedora 3 12-05-2013 05:44 PM
Linux command to find all files in a directory which contain ip addresses. Shakthi Yokesh Linux - Newbie 8 08-19-2012 05:31 AM
Find directory older than x and mv directory with sub files command ajhart Linux - Newbie 4 07-15-2011 05:24 AM
'find' command changes directory access time prollocks Programming 3 10-05-2007 11:57 AM
Command to find similar file names in a directory Ottoguy Linux - Newbie 4 02-02-2006 05:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:50 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration