Полезные команды

Find largest files (Linux)

1️⃣ Find files larger than a specific size

Example: files larger than 500 MB:

find / -type f -size +500M 2>/dev/null
  • / — search from root (you can replace with /var, /home, etc.)

  • 2>/dev/null — hides permission errors

 

Use -exec ls -lh

find / -type f -size +500M 2>/dev/null -exec ls -lh {} \;
  • ls -lh shows sizes in human-readable format (K, M, G).

  • Output example:

-rw-r--r-- 1 root root 1.2G Jan 17 /var/log/mariadb/mariadb.log

-rw-r--r-- 1 www-data www-data 700M Jan 17 /var/log/drupal.log

Limit /var/log/messages

/var/log/messages is managed by rsyslog (or syslog/journald). To limit it:

You can create/modify a file, e.g., /etc/logrotate.d/messages:

/var/log/messages {
daily
rotate 7
compress
delaycompress
missingok
notifempty
size 500M
create 0640 root root
}

Explanation:

  • daily → check every day

  • rotate 7 → keep 7 old logs

  • compress → gzip old logs

  • size 500M → rotate immediately if file > 500 MB

Then test rotation:

logrotate -f /etc/logrotate.d/messages

b) Optional journald approach

If your system uses systemd-journald (many modern CentOS/RHEL/Fedora):

# /etc/systemd/journald.conf
SystemMaxUse=2G
SystemMaxFileSize=200M

Then restart journald:

systemctl restart systemd-journald

This limits all journal logs including /var/log/messages if ForwardToSyslog=yes.

2️⃣ Limit /var/lib/mysql/mysql-slow.log

This is MariaDB’s slow query log. There are two ways:

a) Using logrotate

Create /etc/logrotate.d/mariadb-slow:

/var/lib/mysql/mysql-slow.log { daily rotate 7 compress delaycompress missingok notifempty size 500M create 640 mysql mysql postrotate # Reload MariaDB so it starts a new slow log systemctl kill -s USR1 mariadb endscript }
  • size 500M → rotates if bigger than 500MB

  • postrotate ... USR1 → tells MariaDB to reopen slow lo


b) Limit slow log directly in MariaDB

In /etc/my.cnf:

[mysqld] slow_query_log = 1 slow_query_log_file = /var/lib/mysql/mysql-slow.log long_query_time = 1 log_output = FILE

You cannot directly limit the size inside MariaDB, but with logrotate + USR1 signal you can safely manage it.


Summary recommendation:

  • /var/log/messages → logrotate or journald limit

  • /var/lib/mysql/mysql-slow.log → logrotate + USR1 signal

  • Optional: set daily rotation instead of size if you prefer predictable schedule

 

2026Stable CORE