Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, on linux how can i delete files older than the current month (that is leave only this month's files) from one subdir and recurse every directory? thanks....
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    2

    linux command help

    Hi, on linux how can i delete files older than the current month (that is leave only this month's files) from one subdir and recurse every directory?

    thanks.

  2. #2
    Trusted Penguin Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,392
    This sounds like a homework question, so I'll answer a little cryptically. Take a look down the 'man' page for 'rm', (i.e. do 'man rm' at the command prompt) and look at how you limit what it removes.

    It might also help if you look into the 'find' command, which can search directory trees based on file name, access date, creation date, etc. Read up with 'man find' to look into this.
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Smile

    Quote Originally Posted by Roxoff View Post
    This sounds like a homework question, so I'll answer a little cryptically. Take a look down the 'man' page for 'rm', (i.e. do 'man rm' at the command prompt) and look at how you limit what it removes.

    It might also help if you look into the 'find' command, which can search directory trees based on file name, access date, creation date, etc. Read up with 'man find' to look into this.
    Hi chakytori,
    Check this out this how to use find with exec
    find - Wikipedia, the free encyclopedia

    @ Roxoff -- yes it works like home work question
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  4. #4
    Just Joined!
    Join Date
    Oct 2007
    Posts
    37
    Quote Originally Posted by chakytori View Post
    Hi, on linux how can i delete files older than the current month (that is leave only this month's files) from one subdir and recurse every directory?

    thanks.
    You can use:
    find /{somedir} -mtime +30 -exec rm -rfv {} \;

    I wouldn't recommend using it unless you ARE ABSOLUTELY sure you know what you're doing. A mistake could render your system useless.

  5. #5
    Just Joined!
    Join Date
    Oct 2007
    Posts
    2

    Post Hi!

    This is meant to keep older files in our forum script deleted using a cron job, our forum is simple and we just want to keep the current month files.

    I think there may be an easier way since our script names the files 0704.txt (07 the year and 04 the month) so manually i just need to delete this files:

    0706.txt 0707.txt 0708.txt 0709.txt

    from every directory from the /home/username directory upwards because we have diferent directories for every forum on the site and each one keeps the log files on their dir, how can this be done?

    thanks a lot for the help.

Posting Permissions

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