LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 05-17-2006, 12:49 AM   #1
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)

#/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

that are old files and should be deleted

just want to make sure that the command above will work and not delete
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

Old 05-17-2006, 04:08 AM   #2
Senior Member
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware 14.1 (32 and 64 bit)
Posts: 1,538

Rep: Reputation: 101Reputation: 101
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
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


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 10:54 AM.

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