$i;doneforiin`find.-name"*.log"`;do>$i;done Let’s explain the shell command again: find.-name "*.log" is to find the file with the suffix log in the current directory. cat/dev"/> $i;doneforiin`find.-name"*.log"`;do>$i;done Let’s explain the shell command again: find.-name "*.log" is to find the file with the suffix log in the current directory. cat/dev">

Home  >  Article  >  System Tutorial  >  Use Linux commands to batch delete log files in the current directory

Use Linux commands to batch delete log files in the current directory

WBOY
WBOYforward
2024-01-06 20:58:17831browse

In Linux, sometimes it is necessary to clear the log files in the current directory in batches while retaining the log files.

In fact, it can be done with one line of shell command, let’s take a look.

In the current directory, type the following command:

for i in `find . -name "*.log"`; do cat /dev/null >$i; done

for i in `find . -name "*.log"`;do >$i; done

Use Linux commands to batch delete log files in the current directory

Explain the shell command again:

find . -name "*.log" is to find files with the suffix log in the current directory.

cat /dev/null >$i means to clear the log files found each time.

The above is the detailed content of Use Linux commands to batch delete log files in the current directory. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete