I have to delete oldest directory. But, two of directories does not have to be "included" in this action.
So, directory content looks like this:
[root@myserver backup]# ls -la
total 84
drwxr-xr-x 21 root root 4096 Jun 18 04:10 .
drwxr-xr-x 15 root root 4096 Dec 30 11:42 ..
drwxr-xr-x 9 root root 4096 Jan 11 07:25 2013
drwxr-xr-x 13 root root 4096 Jun 4 08:01 2014
drwxr-xr-x 2 root root 4096 Jun 12 04:20 2014-06-12
drwxr-xr-x 2 root root 4096 Jun 13 04:20 2014-06-13
drwxr-xr-x 2 root root 4096 Jun 14 04:20 2014-06-14
drwxr-xr-x 2 root root 4096 Jun 15 04:20 2014-06-15
drwxr-xr-x 2 root root 4096 Jun 16 04:20 2014-06-16
drwxr-xr-x 2 root root 4096 Jun 17 04:20 2014-06-17
drwxr-xr-x 2 root root 4096 Jun 18 04:20 2014-06-18
[root@myserver backup]#
In this case directory 2014-06-12 have to be deleted, and directories 2013 and 2014 should not be deleted.
I tried by executing next command:
rm -f 'ls -l | grep 2014\- | head -1'
... but it does not deletes anything.
Can you help me how to achieve this?
Thank you in advance!