Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 6912  / 1 Year ago, sun, may 14, 2023, 9:25:36

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?


More From » 18.04

 Answers
0

To delete .log1, .log2, etc. files:



rm *.log[1-9]*



  • rm - Delete files

  • *.log[1-9]* - All files in the current directory that contain .log followed by a digit 1-9 then anything else



To test the command before running it, replace the rm with echo. It will print the matching files.



To truncate .log files:



echo -n | tee *.log



  • echo -n - Print nothing

  • tee *.log - Write from stdin to all .log files in the current directory


[#6179] Monday, May 15, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sator

Total Points: 258
Total Questions: 119
Total Answers: 101

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
;