Shellscript command to remove files starting with a certain string, and older than 3 days

Hi All,

Need help in identifying a shellscript command to remove all files on a server directory, starting with a certain prefix and also older than 3 days.
That means files created with that prefix, today or yesterday, shouldn't be removed.

Thanks,
Dev

try, to list files (safety first):

find search_dir -type f -name "prefix*" -mtime +3 -exec echo rm -f {} \;

to delete, remove the echo .

Can you describe what you have tried?
Also, please explain your actual requirement as this reads like a homework problem.

The timestamp on a file is the number of seconds since Jan 1 1970. It gets turned into human readable dates using rules in your locale. So, simply subtracting three days from right now may not be what you want - calendar days, not 86400 seconds * 3. One day is 86400 seconds.

Try this: where I am it is Mar 30, 2016
so second "0" of Mar 29 is the cutoff

cd /path/to/files
touch -t 201603290000 dummy

Two options:

  1. just the current directory
for f in prefix*
do
     if  [ "$f" -ot dummy ] ; then
       rm $f
     fi
done
  1. whole directory tree starting from current directory
find . -type -name 'prefix*'  ! -newer dummy -exec rm {} \;