Find the answer to your Linux question:
Results 1 to 4 of 4
which command can i use to delete wav files older than 45 days following one give error [root@tekopbx ~]# find /var/spool/asterisk/monitor/ -iname '*.wav' -ctime +45 -exec rm -f {}\; find: ...
  1. #1
    Just Joined!
    Join Date
    Jan 2007
    Posts
    27

    auto delete older den 45 days

    which command can i use to delete wav files older than 45 days

    following one give error

    [root@tekopbx ~]# find /var/spool/asterisk/monitor/ -iname '*.wav' -ctime +45 -exec rm -f {}\;
    find: missing argument to `-exec'
    [root@tekopbx ~]#

  2. #2
    Linux User Krendoshazin's Avatar
    Join Date
    Feb 2005
    Location
    London, England
    Posts
    385
    You've forgotten to put a space inbetween {} and \;

    The command should be:
    Code:
    find /var/spool/asterisk/monitor/ -iname '*.wav' -ctime +45 -exec rm -f {} \;

  3. #3
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    It might be a good idea to restrict the find to files only ( -type f ) and use -delete instead of -exec and rm.

    Other than that, you need to decide to use ctime or mtime.
    I usually use mtime, because: If the file has been modified, I probably want to keep it for a while.
    You must always face the curtain with a bow.

  4. #4
    Linux User Krendoshazin's Avatar
    Join Date
    Feb 2005
    Location
    London, England
    Posts
    385
    Quote Originally Posted by Irithori View Post
    and use -delete instead of -exec and rm.
    Typically we don't use -delete because if you have too many files, then it tends to kick back a “maximum arguments exceeded” error. By using -exec a single process of rm handles the removal of a single file, and that means that many thousands of files can be handled without much of a problem.

    Edit: after I created 1,000,000 text files in a test dir, I ran find with the delete flag but I didn't find a problem with it. However, that doesn't mean that all versions of find won't have this problem, it just means that my particular version doesn't have this problem. Also the size of the files may be a factor as well and therefore I can't consider it a complete test. In the end it's really just a matter of personal preference.
    Last edited by Krendoshazin; 02-05-2012 at 12:36 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...