0

This list of files:

FILE0001
FILE0002
FILE0003
FILE0004
FILE0005
FILE0006
FILE0007
FILE0008
FILE0009
FILE0010

I want to delete all except the following:

FILE0001 
FILE0008 
FILE0010 

How do I do this expression?

There can be a very time-consuming expression, because the files are large. There are other files in that directory. And that can not be affected or removed. Even in the same pattern names.

Example:

FILE0001.1
FILE0002.2
Ivanelson
  • 97
  • 1
  • 10
  • 1
    Please elaborate: are they all in the same folder? Do you already have a static list of files? What have you tried so far? – Jite Jul 15 '14 at 23:34
  • 1
    possible duplicate of [rm all files except some](http://stackoverflow.com/questions/4325216/rm-all-files-except-some) – Lokesh A. R. Jul 15 '14 at 23:35

3 Answers3

4

bash patterns (http://www.gnu.org/software/bash/manual/bashref.html#Pattern-Matching)

shopt -s extglob
echo rm FILE00!(01|08|10)

remove the "echo" if you're satisfied.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • Your question makes no mention of these other files. Go edit the question if you have further requirements you need to tell us. – glenn jackman Jul 16 '14 at 14:20
1
GLOBIGNORE="FILE0001:FILE0008:FILE0010"
echo rm *
Cyrus
  • 84,225
  • 14
  • 89
  • 153
0

Something like this should do the trick assuming all the files are in the same directory that you execute the command and there are no other files or paths that you need to exclude:

find . ! -name 'FILE0001' ! -name 'FILE0008' ! -name 'FILE0010' -exec rm {} /dev/null \;

bated
  • 960
  • 2
  • 15
  • 29