0

I have to delete 60 days older files using find command. I am using following command to delete:

find /etc/tertiary/files/ -type f -name "CDT42D.FDI20T$*.txt" -mtime +60 -print \
| awk -F"/" '{print $NF}' \
| xargs -n 50 rm

but it is failing as the file name has '$' , please suggest what changes needs to be done to above command in order to delete files having special character($) in their names.

choroba
  • 231,213
  • 25
  • 204
  • 289
  • 3
    Use single quotes with -name and not double quotes to avoid any variable expansion attempts. – Raman Sailopal Jun 30 '21 at 10:17
  • Use single quotes for `-name` argument and you don't need to pipe the output to `awk` and `xargs`. Find command has `-delete` flag to delete the entry found `find /etc/tertiary/files/ -type f -name 'CDT42D.FDI20T$*.txt' -mtime +60 -delete` should work – BarathVutukuri Jul 03 '21 at 10:36

1 Answers1

-1

If you want to delete all files that have $ in their names you can use :

rm *$*
Mehan Alavi
  • 278
  • 3
  • 17
  • As per the OP's description, **60 days older** files having `$` in their name need to be deleted... – User123 Jun 30 '21 at 11:25