Home > System Tutorial > LINUX > 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
Release: 2024-01-06 20:58:17
forward
927 people have browsed it

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template