LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-17-2006, 12:49 AM   #1
dtra
Member
 
Registered: Nov 2004
Distribution: fc4
Posts: 104

Rep: Reputation: 15
clarification on find + xargs rm command


hi all

just have a quick question with a cron i am using to clean up the data directory in my mysql dir

basically, we have logging setup on our database cos we've had some issues recently, and we wanted to make sure that we caught anything for the time being

basically we have a script that renames the log file and flushes the mysql logs
and then deletes log files that are older than a certain date (as data is constantly being written, the log files will always be updated)

Code:
#/usr/bin/find /var/lib/mysql/ -type f -mtime +3 | /bin/grep -P '(plain_)+([\d])+(\.log)' | xargs /bin/rm -f
#/usr/bin/find /var/lib/mysql/ -type f -mtime +7 | /bin/grep -P '(plain-bin)+(\.+)' | xargs /bin/rm -f
so we will have eg. plain_20060513.log
plain-bin.000001
plain-bin.000002
plain-bin.000003

that are old files and should be deleted

just want to make sure that the command above will work and not delete
plain.log
plain.000004 (eg. current bin log file, modified 1 minute ago)

and for clarification, when i run ls -lF instead of rm -f after xargs
if there are no results, it shows everything, but if there are no results for rm -f, it won't delete everything?

hope that makes sense

thanks
dave
 
Old 05-17-2006, 04:08 AM   #2
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Ruhr Area, Germany
Distribution: Slackware64 14.0
Posts: 1,524

Rep: Reputation: 94
If I was you I would never rely on others saying the rm thing will work or not. Why not try it yourself, so that you can be sure it does what you want it to do? Copy the logs with the -a option to preserve the timestamps and owner attributes to another folder where you can play around and let your scripts run on them.
 
Old 05-17-2006, 05:56 AM   #3
dtra
Member
 
Registered: Nov 2004
Distribution: fc4
Posts: 104

Original Poster
Rep: Reputation: 15
oh yeah, cool
i had it running, and it seemed to be fine
it's just that when i ran ls i got a fright (cos it listed all the files in the dir)

but i'll just copy some test files and test the script on them
thx
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help me to understand this command: find...| grep -e ... | xargs rm -f ROBERT483599 Red Hat 2 02-14-2006 08:21 AM
du on specific files from find command (use xargs?) fireman949 Linux - Software 2 07-10-2005 01:42 AM
copying files and give new unique names to each file by using xargs command gnim66 Programming 6 06-22-2005 08:29 PM
error with find . | xargs cbonar Linux - Newbie 7 12-09-2004 11:22 AM
PHP: what's wrong with this line (shell_exec, find, xargs, grep)? J_Szucs Programming 3 11-19-2003 07:44 PM


All times are GMT -5. The time now is 04:01 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