-1

let say in /data/in contains common folders, files and archive files with extension .tar.gz

how to remove those .tar.gz only which older than 3 yrs without affecting other common folders and files?

I have a problem how to only grep *.tar.gz only in order to use find command.

1
  • 3
    What commands have you tried? The find command can easily do what you suggest. Just read its man page.
    – EEAA
    Sep 4, 2014 at 4:30

1 Answer 1

2

This will search in /data/in and find files (-type f) with the name ending in .tar.gz which are older (-not -newer) then the timestamp on the file /tmp/end:

touch --date "2011-09-03" /tmp/end # Specify a specific date from 3+ years ago
find /data/in -type f -name "*.tar.gz" -not -newer /tmp/end

You can also use the flags -mtime N to search for files older then the last N days, but sometimes it's easier to simply specify a date instead of calculating the number of days over 3 and some-odd days.

Inspiration from http://www.cyberciti.biz/faq/linux-unix-osxfind-files-by-date/

1

Not the answer you're looking for? Browse other questions tagged .