linux - Script for deleting multiple directories based on directory name using shell or bash script -


i trying write shell script removed directories , contents based on directory name instead of last modified time.

i have following directories in /tmp/ location

2015-05-25 2015-05-26 2015-05-27 2015-05-28 2015-05-29 2015-05-30 2015-05-31 

now delete directories till 2015-05-29. last modified date same directories.

can 1 please suggest?

a straightforward not flexible way (in bash) is:

rm -rf 2015-05-{25..29} 

a more flexible way involve coding:

 ls -d ./2015-* | sort | sed '/2015-06-02/,$d' | xargs rm -r 
  1. sort lexcially directories follow name pattern 2015-*
  2. use 'sed' remove files after (inclusive) 2015-06-02
  3. use 'xargs' delete remaining ones

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -