Find ALL CAPS 8.3 filenames which may contain digits #

Given a directory of files like this:
AD2IWFB6.txt
An_Important_File.txt
BB0IA29Q.txt
C2MMT30I.txt
CANTDELETETHISONE.txt
Y9S29CC0.txt
z.doc
ZZQ0LII7.txt
list the ALL CAPS files which are eight characters long, with or without numbers included, and ending in ".txt" like so:
$ ls -1 | ack ^[A-Z0-9]{8}\.txt$
AD2IWFB6.txt
BB0IA29Q.txt
C2MMT30I.txt
Y9S29CC0.txt
ZZQ0LII7.txt
(find -regex had a problem with the regular expression, so just went with ack instead. ack -g REGEX didn't match the regex either, perhaps because it matches based on both the relative path and filename?)

Delete the matching files by simply piping to xargs:
$ ls -1 | ack ^[A-Z0-9]{8}\.txt$ | xargs rm

/nix | Oct 07, 2011


Subscribe or visit the archives.