0

I have a set of backup directories and I would like to write a bash script to remove all directories created before let's say 22/11. How can I achieve that ?

my directories are in this syntax

backup-{timestamp}

eg:

backup-20200514100830
TheEhsanSarshar
  • 2,677
  • 22
  • 41
  • 2
    You can use `find` with `mtime` fot this. Check this thread --> https://stackoverflow.com/questions/25599094/explaining-the-find-mtime-command – Digvijay S May 14 '20 at 06:52
  • @Ehsansarshar : So for defining the "creation time", you are not interested in any actual timestamp, but want to derive it from the directory name, right? You better also say what operating system you are running. – user1934428 May 14 '20 at 06:59
  • I was searching for a way to find directories by directory name. but I think mtime is the solution – TheEhsanSarshar May 14 '20 at 06:59
  • @Ehsansarshar : _mtime_ is not the **creation** time of the directory, but if you are happy with this, it's ok. – user1934428 May 14 '20 at 07:00
  • You may take also advantage of [If file ... date is older than n days](https://stackoverflow.com/questions/32019432/). – U880D May 14 '20 at 09:55

0 Answers0