Say I have the following file:
test_file-1234-master.tar.gz
I have tried to un tar
using the following commands
tar -xf test_file-[0-9]+-master.tar.gz
tar -xf test_file-[:digit]-master.tar.gz
But no luck. How to match this pattern ?
NOTE: There will be always one file. I'm not trying to open multiple files.
Best Answer
With
ksh
,bash -O extglob
andzsh -o kshglob
only:In
bash
, you have to set theextglob
option first. This+(...)
matches one or more occurrences of the given patterns.[:digit:]
when inside a[...]
bracket expression is a POSIX defined character class which includes Indo-Arabic decimal digits ([[:digit:]]
is the same as[0123456789]
or[0-9]
).It will match:
It will not match:
The
tar
command in your question should then be done like this (with a loop):The more idiomatic short syntax in
zsh
is:(
#
being the extendedglob equivalent of regexp*
, and##
or+
).