I have log files in a folder. These files after some size are creating a new file old_name.log1 and writing to it.
Now there are many files and I can't clear them one by one. I want to delete old_name.log1, old_name.log2 etc and clear old_name.log.
The file_name can be anything. But the file ends with .log and it's extended files ends with .log1, .log2, etc. How to do it?
> old_name.logBut I want to clear multiple files instead of typing each one of their names. – Sreekanth Reddy Balne Feb 07 '19 at 20:03findwith-deleteoption does exactly what you ask. Full command isfind /path/to/dir -regextype sed -regex ".*\.log[1-9]*" -delete. It's common practice to first list files, then delete them to avoid unintended errors. – Sergiy Kolodyazhnyy Feb 07 '19 at 20:08find /path/to/dir -regextype sed -regex ".*\.log[1-9]*" -exec truncate -s 0 {} \;– Sergiy Kolodyazhnyy Feb 07 '19 at 20:17