I need to delete files under directory except latest 2.
I have prepared command to list according to date and delete files. It work when I run manually from command line , however it does not work in crontab.
In crontab,
* * * * * /bin/ls -t /mytest | /usr/bin/tail -n +2 | /usr/bin/xargs rm --
This command works when I run this command from commandline.
Also tried to add command in bash script then called that script from crontab but it did not work again.
How can I run that command via crontab?
bash -c "/bin/ls -t /mytest | /usr/bin/tail -n +2 | /usr/bin/xargs rm --"
as the command to your cron job?MAILTO=
.