Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to write some install scripts for when I install/upgrade Ubuntu. I'm having trouble with fixing logrotate.d:

rotate 7
    reload rsyslog >/dev/null 2>&1 || true

I want to change rotate nnn to rotate 99. It must work for nnn to be any number of digits (normally 1 or 2), yet not affect the postrotate line.

I've tried these two but neither does what I need (and I tested with nnn being 1,2 or 3 digits).

sudo sed  's/rotate[0-9]*/rotate 99/' /etc/logrotate.d/ufw
sudo sed  's/^rotate[0-9]/rotate 99/' /etc/logrotate.d/ufw
share|improve this question

sed 's/rotate [0-9]\+/rotate 99/'


share|improve this answer

rotate[0-9]* replaces rotate followed by zero or more digits, which matches the end of postrotate. rotate[0-9] replaces only one digit. Furthermore you're missing the space after rotate. I think this does what you want; it also handles indented lines:

sudo sed 's/^\( *rotate *\)[0-9][0-9]*/\1 99/' /etc/logrotate.d/ufw

Add the -i option to sed if you want to change the file in place.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.