Common commands for clearing disk space in Unix/Linux

Source: Internet
Author: User

Common commands for clearing disk space in Unix/Linux

Here we recommend several common methods for clearing disk space in Unix/Linux:

Method 1:

Find./-name "*. log *"-exec echo ">" {}\; | sh

This command searches for the files ending with ". log" in the current directory and clears the files. This command is suitable for long-standing log and cannot be deleted directly. When ">" is used for clearing

Add "| sh ".

Method 2:

Find./-name "*. log"-mtime + 1-exec compress {}\;
Find./-name "*. log"-mtime + 1-exec rm {}\;

This command is used to search ". -mtime + 1 indicates that the last modification time of the file exceeds one day, and files that meet the two conditions are compressed or deleted.

.

Method 3:

Ls TRACE _*. log | perl-lne '@ a = stat ($ _); if (time ()-$ a [9])/3600> 6) {print "rm $ _";} '| sh

Ls ULOG. * [0-9] | perl-lne '@ a = stat ($ _); if (time ()-$ a [9])/3600> 24) {print "compress $ _";} '| sh

Ls is familiar to everyone, that is, to list the files in the current folder. The perl-lne is a useful command line parameter in perl, And stat is one of the functions, "$ _" is the wildcard of the file name listed by the preceding ls function. time () is a system function that obtains the current system time, "$ a [9]" is the ninth parameter in file state a obtained by the previous stat function, that is, the file time. "if (time () -$ a [9])/3600> 6) "means that if the current system time minus the file time is greater than 6 hours, the subsequent operations will be performed.

The second command is similar.

In general, you can find the log directories of various programs in the system, determine the time needed to keep the logs of each program, select appropriate commands, and write the cleanup scripts, then configure it to the crontab of the system for regular execution, so as to achieve automatic maintenance of disk space, in this way, the program cannot be executed normally because the system disk space is full due to the large log volume.

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.