Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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've accidently distributed a line to /etc/crontab on many servers and i noticed that there's a typo in this line and i need to change it on all servers.

share|improve this question
up vote 3 down vote accepted

Another option is to fix the typo rather than just delete the last line

sed -i '$ s/typotext/correcttext/ /var/spool/cron/user

You should be able to edit the crontab files directly for newer versions of cron as it checks for changes very minute.

share|improve this answer

If your sed supports in-place editing, then,

sed -i '$d' file

if not, you'll need to use a compound command such as,

cat file | sed '$d' > newfile; mv newfile file
share|improve this answer

use head

user@host$ cat <<EOF > test.txt
user@host$ head -n -1 test.txt | sponge test.txt
user@host$ cat test.txt
share|improve this answer

You can use Vim in Ex mode:

ex -sc 'd|x' /etc/crobtab
  1. d delete line

  2. x save and quit

share|improve this answer

See this forum article on for the answer:

sed -e '$d' input.file > output.file


head -$((wc -l file | awk '{print $1}' - 1)) file

share|improve this answer
Please don't post just a link as an answer but give at least a summary of the info found in this link. – Sven Oct 17 '12 at 10:30

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.