I have directory called /tmp. which stores the log files.
Whenever it becomes full, i want to delete half of files from all log files.
even after deleting the files, if space is more than 90% then it should delete rest of half files.
While deleting files, older files should be deleted first.
Thanks in advance
I am unable to find the logic to divide the files into half part. and delete the older files first. As i am not sure how much files are there in tmp directory, I am bit confused.
ls -t1 >temp;split -nl/2 temp del;while read FN; do echo rm "$FN"; done <delab; rm temp dela?
and remove the echo when you're happy with the proposed deletions. Using xargs might reduce the number of rm calls but will not handle file names with spaces.