Linux SED command help

Posted on 2011-04-26
Last Modified: 2013-12-05
Have a crontab job that runs every night at 5am and deletes any files in the temp folder older than 15 days. Problem is that we've been recieving e-mail alerts (e-mail configured in /etc/aliases sent to root) every time a file is in use.. We don't want tog et these alerts so I want to re-direct them to /dev/null .

Crontab entry:
00 05 * * *     root find /tmp -mtime +15 -prune -exec rm -Rf {} >/dev/null   /;
PS: The syntax above to re-direct errors is wrong.

So I'm trying to run a script to change that line in every crontab on every server.
Problem is with the & character. In SED, this character is considered a replacement character.
I would like for sed to use it as fixed character.

Here's the command I'm using in my script:

sed -i \"s#{} >/dev/null#>{} >/dev/null 2>&1#\"

I tried a few things, like using ascii codes, or putting '&' in the string.. After searching on google and expert exchange for a few hours. and trying many things.. Can't seem to get this to work. Anyone know how to fix this?

Thank you,


Question by:trembe
    LVL 8

    Accepted Solution

    sed -i \"s#{} >\/dev\/null#\>{}\ \>\/dev\/null 2\>\&1#\"
    LVL 31

    Expert Comment

    Try this:
     sed  "s#{} >/dev/null#>{} >/dev/null 2>\&1#"
    LVL 31

    Expert Comment

    Sorry, I removed -i

    Here it is:

    sed  "s#{} >/dev/null#>{} >/dev/null 2>\&1#"

    Open in new window

    LVL 31

    Assisted Solution

    sed -i "s#{} >/dev/null#>{} >/dev/null 2>\&1#"

    Author Comment

    Thank you both. works great.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Creating a Samba server for a small office. Ubuntu Linux and Samba can breathe new life into a retired PC and save an office money on new hardware/software. Our example server will have two hard disks, one exclusively for storing shared data. …
    This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now