If you have a file for every day, you can use a sequence expression in braces:
cp -p system-2013-01-{01..15}.log /elsewhere
If you don't have a file for every day, you can use character patterns.
cp -p system-2013-01-0[1-9].log system-2013-01-1[0-5].log /elsewhere
If there is no matching file in one of the two ranges, the pattern will be left unexpanded. Set the nullglob option (bash-specific) to avoid this (shopt nullglob
).
Zsh makes this easier thanks to its <start-stop>
numeric range glob pattern.
cp -p system-2013-01-<1-15>.log /elsewhere
A different approach that doesn't require zsh and scales well to more complex cases is to use find
to generate the list of files. You don't need to worry about non-matches: cp
will be executed for each match.
find . \( -name 'system-2013-01-0[1-9].log' -o -name 'system-2013-01-1[0-5].log' \) -exec cp -p {} /elsewhere \;
Add -type d -prune -o
after find .
to avoid recursing into subdirectories.