Working fine:
==> scp my_log-bin.01393[0-9] [email protected]:/backup/
error - No such file or directory:
==> scp my_log-bin.0139[30-99] [email protected]:/backup/
Working fine:
==> scp my_log-bin.01393[0-9] [email protected]:/backup/
error - No such file or directory:
==> scp my_log-bin.0139[30-99] [email protected]:/backup/
The extraction will be handled by your shell.
If your shell is bash, []
matches any one of the enclosed character and [30-99]
does not match two characters.
How about using the following instead:
scp my_log-bin.0139[3-9][0-9] [email protected]:/backup/
As well as the [0-9] you can use curly braces and .. notation.
scp my_log-bin.0139{30..99} [email protected]:/backup/
[30-99]
, in shell pattern ("glob") notation, means "3
, or a digit in the range 0-9
, or 9
", i.e. it's the same as [0-9]
.
What you want is
# build list of files; note, won't work when filename contains a space or colon
files=""
for i in `seq 30 99`; do
files="$files my_log-bin.$i"
done
scp $files [email protected]:/backup/
bash(1)
implements [n-m]
ranges for filename expansions in a manner similar to regular expressions -- the range represents a single character:
$ for i in `seq 1 100` ; do touch $i ; done
$ ls
1 13 18 22 27 31 36 40 45 5 54 59 63 68 72 77 81 86 90 95
10 14 19 23 28 32 37 41 46 50 55 6 64 69 73 78 82 87 91 96
100 15 2 24 29 33 38 42 47 51 56 60 65 7 74 79 83 88 92 97
11 16 20 25 3 34 39 43 48 52 57 61 66 70 75 8 84 89 93 98
12 17 21 26 30 35 4 44 49 53 58 62 67 71 76 80 85 9 94 99
$ echo [0-9]
1 2 3 4 5 6 7 8 9
$ echo [30-99]
1 2 3 4 5 6 7 8 9
It also works with letters:
$ touch a b c d e f g h i j k l m n o p q r s t u v w x y z
$ echo [f-l]
f g h i j k l
The full details from the manpage:
[...] Matches any one of the enclosed characters. A pair of
characters separated by a hyphen denotes a range
expression; any character that sorts between those two
characters, inclusive, using the current locale's
collating sequence and character set, is matched. If
the first character following the [ is a ! or a ^
then any character not enclosed is matched. The
sorting order of characters in range expressions is
determined by the current locale and the value of the
LC_COLLATE shell variable, if set. A - may be matched
by including it as the first or last character in the
set. A ] may be matched by including it as the first
character in the set.
Within [ and ], character classes can be specified
using the syntax [:class:], where class is one of the
following classes defined in the POSIX standard:
alnum alpha ascii blank cntrl digit graph lower print
punct space upper word xdigit
A character class matches any character belonging to
that class. The word character class matches letters,
digits, and the character _.
Within [ and ], an equivalence class can be specified
using the syntax [=c=], which matches all characters
with the same collation weight (as defined by the
current locale) as the character c.
Within [ and ], the syntax [.symbol.] matches the
collating symbol symbol.
The shell issue has been dealt well, but if the underlying problem is to only copy over new files, then I solve this problem by using rsync:
rsync --progress -tvprogul my_log-bin.* [email protected]:/backup/
and let rsync work out which files are already over there.
==> scp my_log-bin.0139[3-9][0-9] [email protected]:/backup/