@granidier - If you're looking at deleting old files then
@Robs suggestion is one way of doing it - if the date of the logs creation is included in the file-name. Then you can simply search for files with filenames containing dates that are older than your cut-off and remove them.
However - if you want to delete files that are older than X days - personally I'd run with this:
Bash:
find /path/to/logfiles/ -type f -mtime +X -delete
Where /path/to/logfiles is the path to the logfiles and X is the number of days e.g. 30, or 100, or whatever!
My rationale for this is simple:
If the mtime hasn't changed in over X days - then the content of the file hasn't changed in over X days - Therefore it's pretty safe to say that the log-file is at least X days old and is a solid candidate for removal!
Also you will almost certainly need to be root in order to execute the above command, so either su to root, or use sudo - if it is set-up on the CentOS system.
Also - because of the huge number of files - this process will almost certainly take a long time to complete. So if you want to be able to continue using the terminal whilst the job is running, you might want to consider running find in the background by putting an apersand & at the end of the command.
e.g.
Bash:
find /path/to/logfiles -type f -mtime +X -delete &
Again where /path/to/logfiles is the location of the logs and X is the number of days. And once again, you'll also need to make sure you're running the command as root.
When you run that - the terminal will display a PID and a job number and you will be able to continue to use the terminal whilst the job is running in the background.
I don't know how much you know about job-control, but JIC you don't know:
You can see what jobs you have running in the background using the
jobs -l
command. There are a number of other options that can be used with the jobs command to allow you to view only running jobs, or only stopped jobs etc etc.
I won't list them all here, but you can read about them using the command
help jobs
If you need to temporarily pause the background job, or restart it, or properly kill it - you can use the
kill
command to send various signals to the job using it's PID.
So if your find command is running in the background and has a PID of 4587, and you want to pause it you would use:
or
That will pause the background job by sending the process the SIGSTOP signal.
And then to resume it:
or
That will resume the job running in the background by sending the SIGCONT signal.
And if you need to completely kill it:
or
That will send the SIGTERM signal to the process, which should allow the process to cleanly shut-down. Any pending file-writes are completed and the process can clean up after itself as it shuts down.
After sending a signal to a job that has been started in the background - you can use the
jobs
or
jobs -l
command to list all jobs and verify that the signal you sent has had the required effect.
So after sending SIGTERM, you can check to see if the process has actually ended using the
jobs
command.
If sending SIGTERM fails to kill the process the absolute final resort is SIGKILL:
or
That will send the SIGKILL signal which will force the process to end no matter what - but this should only be used in extreme circumstances because it can potentially leave corrupted files behind in its wake. For example if the process is in the middle of writing to a file and it receives the SIGKILL signal, it will just end mid-write, leaving the file in a potentially corrupt/incomplete state.
To see more about the signals that can be sent via kill, read the manpage for kill
man kill
.