How To Find Error_log Files In Linux
List the Error Log files with its disk space usage details:
# find . -type f -iname error_log -exec du -sh {} \;
- type : Specify the type to find.
- iname: Specify the name to find.
- exec: Execute the “du -sch” and lists the output with file size.
How To Find And Delete Error_log Files In Linux
# find . -type f -iname error_log -delete
- delete: This switch removes the outputs from the find command.
How To Find All The Error_log Files Larger Than 1 GB
To find all the error_log files larger than 1 GB (1,073,741,824 bytes) in the current directory and its subdirectories, you can use the following command:
find . -type f -name "error_log" -size +1000000000c -exec ls -lh {} \;
Explanation of the command options:
find .
: start searching from the current directory (.
)-type f
: only look for files (not directories)-name "error_log"
: only consider files with the name “error_log”-size +1000000000c
: only consider files that are larger than 1 GB (1,000,000,000 bytes)-exec ls -lh {} \;
: run thels -lh
command on each file found, displaying its size in human-readable format. The{}
placeholder is replaced with the path to each file, and the\;
is used to end theexec
command.
The ls -lh
command displays information about the files, including their size, permissions, and modification date. The -h
option makes the size human-readable, so it will show values like “1.0G” instead of “1000000000”.
How To Find And Remove All The Error_log Files Larger Than 1 GB
find . -type f -name "error_log" -size +1000000000c -exec rm {} \;
Explanation of the command options:
find .
: start searching from the current directory (.
)-type f
: only look for files (not directories)-name "error_log"
: only consider files with the name “error_log”-size +1000000000c
: only consider files that are larger than 1 GB (1,000,000,000 bytes)-exec rm {} \;
: run therm
command on each file found, removing it from the file system. The{}
placeholder is replaced with the path to each file, and the\;
is used to end theexec
command.
Note: The rm
command permanently deletes files. Make sure you want to delete the files before running this command, as it does not send the files to the trash bin or provide any means to recover the deleted files.
How To Find And Delete Error_log Files Using A Cron Job
If you want to automatically remove all the error_log files which are being generated, you can achieve this by setting up a cron job.
The command that the cron job should execute is:
/bin/find /home/user -type f -iname error_log -delete
Example: 0 * * * * /bin/find /home/eatat/ -type f -iname error_log -delete