Find the answer to your Linux question:
Results 1 to 5 of 5
Hi Guys, I am new to unix, I am looking for a script to delete files older than 7 days but i also want to exclude certain directories (like arch,log ...
  1. #1
    Just Joined!
    Join Date
    Jan 2011
    Posts
    2

    delete files older than 7 days

    Hi Guys,

    I am new to unix, I am looking for a script to delete files older than 7 days but i also want to exclude certain directories (like arch,log .....) and also some files with extensions ( like .ksh, .ch, ..............) in directories and sub directories

    Thanks in advance

    sunny

  2. #2
    Just Joined!
    Join Date
    Dec 2010
    Location
    India
    Posts
    45
    U can get the files 7 days older by using find command with -mtime option .

    and then from the list of file use regular expression and delete the files that is not having .csh or .ksh extention.
    you try out and write the script . if there is any problem we will correct that.

    for reference check man find .

  3. #3
    Just Joined!
    Join Date
    Jan 2011
    Posts
    2
    Hi piyu,

    I have written the command it is checking in the directory only but not checking in sub directories



    find tdarch/* -prune -type f ! \( -name "*.ksh" -o -name "*.sh" -o -name "*.c" \) -mmin +1 > tdlog/4.log
    Last edited by sunnyece51; 01-03-2011 at 02:42 PM. Reason: Modification

  4. #4
    Just Joined!
    Join Date
    Jun 2010
    Posts
    6
    man find

    -prune prevents going into subdirectories. Just get rid of that option and try again.

  5. #5
    Just Joined!
    Join Date
    Dec 2010
    Location
    India
    Posts
    45
    dufftime told you the problem but i want to suggest one thing. before writing any command just go through the man page of that command and ensure that whatever options you are using you know them why are u using that
    happy learning

Posting Permissions

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