How to clear all files in a folder ending with `.log`? [duplicate]
This question already has an answer here:
How to truncate all logfiles?
4 answers
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?
18.04 files delete
marked as duplicate by Sergiy Kolodyazhnyy, Elder Geek, Charles Green, Soren A, Kulfy Feb 8 at 16:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to truncate all logfiles?
4 answers
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?
18.04 files delete
marked as duplicate by Sergiy Kolodyazhnyy, Elder Geek, Charles Green, Soren A, Kulfy Feb 8 at 16:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to truncate all logfiles?
4 answers
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?
18.04 files delete
This question already has an answer here:
How to truncate all logfiles?
4 answers
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?
This question already has an answer here:
How to truncate all logfiles?
4 answers
18.04 files delete
18.04 files delete
asked Feb 7 at 18:30
spiritsreespiritsree
1033
1033
marked as duplicate by Sergiy Kolodyazhnyy, Elder Geek, Charles Green, Soren A, Kulfy Feb 8 at 16:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Sergiy Kolodyazhnyy, Elder Geek, Charles Green, Soren A, Kulfy Feb 8 at 16:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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
How to clear these files using the command line? I know how to find. To clear a single file I would use> old_name.log
But I want to clear multiple files instead of typing each one of their names.
– spiritsree
Feb 7 at 20:03
@Shameless Oh, I thought "clear" meant "delete". Usually I've heard emptying a file called "erasing" or maybe "zeroing" or "wiping". I'll revise the answer to do that.
– wjandrea
Feb 7 at 20:12
1
@wjandrea this won't work right. Your rm code won't delete log files named *.log.01, *.log.02, etc. Your tee code won't get ANY log files with any names like *.log.1, *.log.01, etc. And, you don't want to touch any *.log file, as it's probably an open active file.
– heynnema
Feb 8 at 15:59
@heynnema You're totally right. My answer is meant to answer the question exactly as asked, regardless of effects. I don't know enough about log files to really comment on it anyway.
– wjandrea
Feb 8 at 16:06
Comments are not for extended discussion; this conversation has been moved to chat.
– Seth♦
Feb 9 at 0:57
add a comment |
Note that OP apparently wants to truncate files. In such case, the desired command is
find /path/to/dir -regextype sed -regex ".*.log[1-9]*" -exec truncate -s 0 {} ;
Alternatively, in bash
shopt -s globstar
truncate -s 0 **/*.log[1-9]
If you want to clear out any file that has .log
in the name
find /path/to/dir -name "*.log*"
If you target .log[digit]
specifically, use
find /path/to/dir -regextype sed -regex ".*.log[1-9]*"
Once you verify either of these two commands find the files you want, append -delete
to the command for actual removal
How to clear these files using the command line? I know how to find. To clear a single file I would use> old_name.log
But I want to clear multiple files instead of typing each one of their names.
– spiritsree
Feb 7 at 20:03
1
@Shameless Please read the last sentence in my answer.find
with-delete
option 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 7 at 20:08
1
@Shameless If by clear you mean "keep filename, but delete contents", then you wantfind /path/to/dir -regextype sed -regex ".*.log[1-9]*" -exec truncate -s 0 {} ;
– Sergiy Kolodyazhnyy
Feb 7 at 20:17
add a comment |
Quick and dirty... assuming that you have permissions for these log files and directory itself... and you wish to delete the .log* files...
- in a
Files
window, open the directory where the log files are located - search for .log files
Select All
, control-click any files to exclude (like the active and open *.log)- then
Move to Trash
Note: if you wish to "clear" the .log file, close the application that makes the current .log file, then delete the current .log file with Move to Trash
, and then right-click in the folder, select New Document
, then Blank Document
, and Rename...
using the correct .log filename.
Well Done! Everyone thinks command line is the only tool for Linux, but GUI indeed works too!
– EODCraft Staff
Feb 7 at 20:51
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
How to clear these files using the command line? I know how to find. To clear a single file I would use> old_name.log
But I want to clear multiple files instead of typing each one of their names.
– spiritsree
Feb 7 at 20:03
@Shameless Oh, I thought "clear" meant "delete". Usually I've heard emptying a file called "erasing" or maybe "zeroing" or "wiping". I'll revise the answer to do that.
– wjandrea
Feb 7 at 20:12
1
@wjandrea this won't work right. Your rm code won't delete log files named *.log.01, *.log.02, etc. Your tee code won't get ANY log files with any names like *.log.1, *.log.01, etc. And, you don't want to touch any *.log file, as it's probably an open active file.
– heynnema
Feb 8 at 15:59
@heynnema You're totally right. My answer is meant to answer the question exactly as asked, regardless of effects. I don't know enough about log files to really comment on it anyway.
– wjandrea
Feb 8 at 16:06
Comments are not for extended discussion; this conversation has been moved to chat.
– Seth♦
Feb 9 at 0:57
add a comment |
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
How to clear these files using the command line? I know how to find. To clear a single file I would use> old_name.log
But I want to clear multiple files instead of typing each one of their names.
– spiritsree
Feb 7 at 20:03
@Shameless Oh, I thought "clear" meant "delete". Usually I've heard emptying a file called "erasing" or maybe "zeroing" or "wiping". I'll revise the answer to do that.
– wjandrea
Feb 7 at 20:12
1
@wjandrea this won't work right. Your rm code won't delete log files named *.log.01, *.log.02, etc. Your tee code won't get ANY log files with any names like *.log.1, *.log.01, etc. And, you don't want to touch any *.log file, as it's probably an open active file.
– heynnema
Feb 8 at 15:59
@heynnema You're totally right. My answer is meant to answer the question exactly as asked, regardless of effects. I don't know enough about log files to really comment on it anyway.
– wjandrea
Feb 8 at 16:06
Comments are not for extended discussion; this conversation has been moved to chat.
– Seth♦
Feb 9 at 0:57
add a comment |
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
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
edited Feb 8 at 1:15
answered Feb 7 at 18:38
wjandreawjandrea
9,47842664
9,47842664
How to clear these files using the command line? I know how to find. To clear a single file I would use> old_name.log
But I want to clear multiple files instead of typing each one of their names.
– spiritsree
Feb 7 at 20:03
@Shameless Oh, I thought "clear" meant "delete". Usually I've heard emptying a file called "erasing" or maybe "zeroing" or "wiping". I'll revise the answer to do that.
– wjandrea
Feb 7 at 20:12
1
@wjandrea this won't work right. Your rm code won't delete log files named *.log.01, *.log.02, etc. Your tee code won't get ANY log files with any names like *.log.1, *.log.01, etc. And, you don't want to touch any *.log file, as it's probably an open active file.
– heynnema
Feb 8 at 15:59
@heynnema You're totally right. My answer is meant to answer the question exactly as asked, regardless of effects. I don't know enough about log files to really comment on it anyway.
– wjandrea
Feb 8 at 16:06
Comments are not for extended discussion; this conversation has been moved to chat.
– Seth♦
Feb 9 at 0:57
add a comment |
How to clear these files using the command line? I know how to find. To clear a single file I would use> old_name.log
But I want to clear multiple files instead of typing each one of their names.
– spiritsree
Feb 7 at 20:03
@Shameless Oh, I thought "clear" meant "delete". Usually I've heard emptying a file called "erasing" or maybe "zeroing" or "wiping". I'll revise the answer to do that.
– wjandrea
Feb 7 at 20:12
1
@wjandrea this won't work right. Your rm code won't delete log files named *.log.01, *.log.02, etc. Your tee code won't get ANY log files with any names like *.log.1, *.log.01, etc. And, you don't want to touch any *.log file, as it's probably an open active file.
– heynnema
Feb 8 at 15:59
@heynnema You're totally right. My answer is meant to answer the question exactly as asked, regardless of effects. I don't know enough about log files to really comment on it anyway.
– wjandrea
Feb 8 at 16:06
Comments are not for extended discussion; this conversation has been moved to chat.
– Seth♦
Feb 9 at 0:57
How to clear these files using the command line? I know how to find. To clear a single file I would use
> old_name.log
But I want to clear multiple files instead of typing each one of their names.– spiritsree
Feb 7 at 20:03
How to clear these files using the command line? I know how to find. To clear a single file I would use
> old_name.log
But I want to clear multiple files instead of typing each one of their names.– spiritsree
Feb 7 at 20:03
@Shameless Oh, I thought "clear" meant "delete". Usually I've heard emptying a file called "erasing" or maybe "zeroing" or "wiping". I'll revise the answer to do that.
– wjandrea
Feb 7 at 20:12
@Shameless Oh, I thought "clear" meant "delete". Usually I've heard emptying a file called "erasing" or maybe "zeroing" or "wiping". I'll revise the answer to do that.
– wjandrea
Feb 7 at 20:12
1
1
@wjandrea this won't work right. Your rm code won't delete log files named *.log.01, *.log.02, etc. Your tee code won't get ANY log files with any names like *.log.1, *.log.01, etc. And, you don't want to touch any *.log file, as it's probably an open active file.
– heynnema
Feb 8 at 15:59
@wjandrea this won't work right. Your rm code won't delete log files named *.log.01, *.log.02, etc. Your tee code won't get ANY log files with any names like *.log.1, *.log.01, etc. And, you don't want to touch any *.log file, as it's probably an open active file.
– heynnema
Feb 8 at 15:59
@heynnema You're totally right. My answer is meant to answer the question exactly as asked, regardless of effects. I don't know enough about log files to really comment on it anyway.
– wjandrea
Feb 8 at 16:06
@heynnema You're totally right. My answer is meant to answer the question exactly as asked, regardless of effects. I don't know enough about log files to really comment on it anyway.
– wjandrea
Feb 8 at 16:06
Comments are not for extended discussion; this conversation has been moved to chat.
– Seth♦
Feb 9 at 0:57
Comments are not for extended discussion; this conversation has been moved to chat.
– Seth♦
Feb 9 at 0:57
add a comment |
Note that OP apparently wants to truncate files. In such case, the desired command is
find /path/to/dir -regextype sed -regex ".*.log[1-9]*" -exec truncate -s 0 {} ;
Alternatively, in bash
shopt -s globstar
truncate -s 0 **/*.log[1-9]
If you want to clear out any file that has .log
in the name
find /path/to/dir -name "*.log*"
If you target .log[digit]
specifically, use
find /path/to/dir -regextype sed -regex ".*.log[1-9]*"
Once you verify either of these two commands find the files you want, append -delete
to the command for actual removal
How to clear these files using the command line? I know how to find. To clear a single file I would use> old_name.log
But I want to clear multiple files instead of typing each one of their names.
– spiritsree
Feb 7 at 20:03
1
@Shameless Please read the last sentence in my answer.find
with-delete
option 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 7 at 20:08
1
@Shameless If by clear you mean "keep filename, but delete contents", then you wantfind /path/to/dir -regextype sed -regex ".*.log[1-9]*" -exec truncate -s 0 {} ;
– Sergiy Kolodyazhnyy
Feb 7 at 20:17
add a comment |
Note that OP apparently wants to truncate files. In such case, the desired command is
find /path/to/dir -regextype sed -regex ".*.log[1-9]*" -exec truncate -s 0 {} ;
Alternatively, in bash
shopt -s globstar
truncate -s 0 **/*.log[1-9]
If you want to clear out any file that has .log
in the name
find /path/to/dir -name "*.log*"
If you target .log[digit]
specifically, use
find /path/to/dir -regextype sed -regex ".*.log[1-9]*"
Once you verify either of these two commands find the files you want, append -delete
to the command for actual removal
How to clear these files using the command line? I know how to find. To clear a single file I would use> old_name.log
But I want to clear multiple files instead of typing each one of their names.
– spiritsree
Feb 7 at 20:03
1
@Shameless Please read the last sentence in my answer.find
with-delete
option 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 7 at 20:08
1
@Shameless If by clear you mean "keep filename, but delete contents", then you wantfind /path/to/dir -regextype sed -regex ".*.log[1-9]*" -exec truncate -s 0 {} ;
– Sergiy Kolodyazhnyy
Feb 7 at 20:17
add a comment |
Note that OP apparently wants to truncate files. In such case, the desired command is
find /path/to/dir -regextype sed -regex ".*.log[1-9]*" -exec truncate -s 0 {} ;
Alternatively, in bash
shopt -s globstar
truncate -s 0 **/*.log[1-9]
If you want to clear out any file that has .log
in the name
find /path/to/dir -name "*.log*"
If you target .log[digit]
specifically, use
find /path/to/dir -regextype sed -regex ".*.log[1-9]*"
Once you verify either of these two commands find the files you want, append -delete
to the command for actual removal
Note that OP apparently wants to truncate files. In such case, the desired command is
find /path/to/dir -regextype sed -regex ".*.log[1-9]*" -exec truncate -s 0 {} ;
Alternatively, in bash
shopt -s globstar
truncate -s 0 **/*.log[1-9]
If you want to clear out any file that has .log
in the name
find /path/to/dir -name "*.log*"
If you target .log[digit]
specifically, use
find /path/to/dir -regextype sed -regex ".*.log[1-9]*"
Once you verify either of these two commands find the files you want, append -delete
to the command for actual removal
edited Feb 7 at 20:27
answered Feb 7 at 18:37
Sergiy KolodyazhnyySergiy Kolodyazhnyy
74.7k9155325
74.7k9155325
How to clear these files using the command line? I know how to find. To clear a single file I would use> old_name.log
But I want to clear multiple files instead of typing each one of their names.
– spiritsree
Feb 7 at 20:03
1
@Shameless Please read the last sentence in my answer.find
with-delete
option 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 7 at 20:08
1
@Shameless If by clear you mean "keep filename, but delete contents", then you wantfind /path/to/dir -regextype sed -regex ".*.log[1-9]*" -exec truncate -s 0 {} ;
– Sergiy Kolodyazhnyy
Feb 7 at 20:17
add a comment |
How to clear these files using the command line? I know how to find. To clear a single file I would use> old_name.log
But I want to clear multiple files instead of typing each one of their names.
– spiritsree
Feb 7 at 20:03
1
@Shameless Please read the last sentence in my answer.find
with-delete
option 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 7 at 20:08
1
@Shameless If by clear you mean "keep filename, but delete contents", then you wantfind /path/to/dir -regextype sed -regex ".*.log[1-9]*" -exec truncate -s 0 {} ;
– Sergiy Kolodyazhnyy
Feb 7 at 20:17
How to clear these files using the command line? I know how to find. To clear a single file I would use
> old_name.log
But I want to clear multiple files instead of typing each one of their names.– spiritsree
Feb 7 at 20:03
How to clear these files using the command line? I know how to find. To clear a single file I would use
> old_name.log
But I want to clear multiple files instead of typing each one of their names.– spiritsree
Feb 7 at 20:03
1
1
@Shameless Please read the last sentence in my answer.
find
with -delete
option does exactly what you ask. Full command is find /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 7 at 20:08
@Shameless Please read the last sentence in my answer.
find
with -delete
option does exactly what you ask. Full command is find /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 7 at 20:08
1
1
@Shameless If by clear you mean "keep filename, but delete contents", then you want
find /path/to/dir -regextype sed -regex ".*.log[1-9]*" -exec truncate -s 0 {} ;
– Sergiy Kolodyazhnyy
Feb 7 at 20:17
@Shameless If by clear you mean "keep filename, but delete contents", then you want
find /path/to/dir -regextype sed -regex ".*.log[1-9]*" -exec truncate -s 0 {} ;
– Sergiy Kolodyazhnyy
Feb 7 at 20:17
add a comment |
Quick and dirty... assuming that you have permissions for these log files and directory itself... and you wish to delete the .log* files...
- in a
Files
window, open the directory where the log files are located - search for .log files
Select All
, control-click any files to exclude (like the active and open *.log)- then
Move to Trash
Note: if you wish to "clear" the .log file, close the application that makes the current .log file, then delete the current .log file with Move to Trash
, and then right-click in the folder, select New Document
, then Blank Document
, and Rename...
using the correct .log filename.
Well Done! Everyone thinks command line is the only tool for Linux, but GUI indeed works too!
– EODCraft Staff
Feb 7 at 20:51
add a comment |
Quick and dirty... assuming that you have permissions for these log files and directory itself... and you wish to delete the .log* files...
- in a
Files
window, open the directory where the log files are located - search for .log files
Select All
, control-click any files to exclude (like the active and open *.log)- then
Move to Trash
Note: if you wish to "clear" the .log file, close the application that makes the current .log file, then delete the current .log file with Move to Trash
, and then right-click in the folder, select New Document
, then Blank Document
, and Rename...
using the correct .log filename.
Well Done! Everyone thinks command line is the only tool for Linux, but GUI indeed works too!
– EODCraft Staff
Feb 7 at 20:51
add a comment |
Quick and dirty... assuming that you have permissions for these log files and directory itself... and you wish to delete the .log* files...
- in a
Files
window, open the directory where the log files are located - search for .log files
Select All
, control-click any files to exclude (like the active and open *.log)- then
Move to Trash
Note: if you wish to "clear" the .log file, close the application that makes the current .log file, then delete the current .log file with Move to Trash
, and then right-click in the folder, select New Document
, then Blank Document
, and Rename...
using the correct .log filename.
Quick and dirty... assuming that you have permissions for these log files and directory itself... and you wish to delete the .log* files...
- in a
Files
window, open the directory where the log files are located - search for .log files
Select All
, control-click any files to exclude (like the active and open *.log)- then
Move to Trash
Note: if you wish to "clear" the .log file, close the application that makes the current .log file, then delete the current .log file with Move to Trash
, and then right-click in the folder, select New Document
, then Blank Document
, and Rename...
using the correct .log filename.
edited Feb 9 at 0:31
answered Feb 7 at 18:41
heynnemaheynnema
21.1k22360
21.1k22360
Well Done! Everyone thinks command line is the only tool for Linux, but GUI indeed works too!
– EODCraft Staff
Feb 7 at 20:51
add a comment |
Well Done! Everyone thinks command line is the only tool for Linux, but GUI indeed works too!
– EODCraft Staff
Feb 7 at 20:51
Well Done! Everyone thinks command line is the only tool for Linux, but GUI indeed works too!
– EODCraft Staff
Feb 7 at 20:51
Well Done! Everyone thinks command line is the only tool for Linux, but GUI indeed works too!
– EODCraft Staff
Feb 7 at 20:51
add a comment |