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
- sort lexcially directories follow name pattern 2015-*
- use 'sed' remove files after (inclusive) 2015-06-02
- use 'xargs' delete remaining ones
Comments
Post a Comment