0

I have a couple of files which follow this syntax:

  • _yyyy-mm-dd_hhhmmm.

Example:

  • _2010-01-01_00h10m.
  • _2010-01-01_01h10m.
  • _2010-01-01_02h10m.
  • _2010-01-01_03h10m.
  • ...
  • _2010-01-01_23h10m.
  • _2010-02-01_00h10m.
  • _2010-02-01_01h10m.
  • _2010-02-01_02h10m.
  • ...
  • _2010-02-01_23h10m.
  • ...
  • _2010-12-01_23h10m.

I would like to keep only this files

  • _2010-01-01_00h10m.
  • _2010-02-01_00h10m.
  • _2010-03-01_00h10m.
  • ...
  • _2010-12-01_00h10m.

and delete the others. or maybe move them to a subdirectory to be safe...

Does someone has a smart on-liner for this challenge?

Thanks, Udo

udo
  • 8,061

2 Answers2

2

In bash:

shopt -s extglob
rm !(*_2010-??-01_00h10m.*)
1

very naive way

mkdir keep_these
mkdir remove_these
mv *_00h10m* keep_these
mv *.* remove_these

or a oneliner

ls * | grep -v "_00h10m" | while read a; do mv $a /tmp; done
Nifle
  • 34,998