Home > bash, Linux > Bash oneliner HOWTO to remove all the logs but from the last three days in case you face the “Argument list too long” issue

Bash oneliner HOWTO to remove all the logs but from the last three days in case you face the “Argument list too long” issue


# we assume the target directory is /var/spool/bsms/main/errors/
cd /var/spool/bsms/main/errors/; ls -lrt  | egrep ".sql$" | egrep -v "$(date +"%Y-%m-%d")|$(date -d '1 day ago' +"%Y-%m-%d")|$(date -d '2 day ago' +"%Y-%m-%d")" | awk '{print$8}' | xargs --no-run-if-empty -icrap rm -f crap

Slackware4Life πŸ˜›

Advertisements
  1. January 30, 2013 at 4:21 pm

    I think you could do the bash oneliner in awk but you would probably need to generate some intermediate files and end with a cleanup. Give me until February

  2. dragkh
    January 30, 2013 at 4:44 pm

    yep I can , but it will be longer πŸ™‚
    cheers

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: