find . -maxdepth 1 -mindepth 1 -not -type f -name "Type1_201608*.xml"
This means: for the files in the current directory (. -maxdepth 1 -mindepth 1
), list the files that are not regular files (-not -type f
), and that have a name matching "Type1_201608*.xml
.
Since you want to list only files that match Type1_*.xml
, your command is going to have to include this pattern somehere! And since you want to act on regular files, don't negate -type f
.
find . -maxdepth 1 -mindepth 1 -type f -name "Type1_*.xml" ! -name "Type1_201608*.xml"
Don't parse the output of find
. Use -exec
, that's what it's for.
find . -maxdepth 1 -mindepth 1 -type f -name "Type1_*.xml" ! -name "Type1_201608*.xml" -exec gzip -5 {} +
With modern shells, if the pattern Type1_*.xml
doesn't match any directory or any symbolic link that you want to exclude, you don't need find
for this. You can use ksh extended glob patterns, which are also available in bash.
shopt -s extglob
gzip -5 Type1_!(201608*).xml
In zsh, you can enable ksh extended glob patterns, but you can also use zsh's own.
setopt extended_glob
gzip -5 Type1_*.xml~Type1_201608*
Or
gzip -5 Type1_(^201608*).xml
And in zsh, if you want to ensure that only regular files are matched, you can use a glob qualifier.
setopt extended_glob
gzip -5 Type1_(^201608*).xml(.)
-type f -name "Type1_*xml" -not -name '*_201608*'
– Costas Aug 17 '16 at 08:15find * -prune -type f -name "Type1_*xml" -not -name '*_201608*' -exec gzip -5 {} +
– Costas Aug 17 '16 at 08:22