Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is a simple question. I'm trying to copy all of the files in the current directory that start with "axis-2" and end with ".jar" into a target directory, let's say it's ~/MyDirectory. My first thought was to try

cp '^axis2.*jar$' ~/MyDirectory

But this isn't working. I'm not even sure I can use regular expressions with cp. I also haven't really used regular expressions in a while and my syntax could be totally off. When I try this cp just outputs a "No such file or directory" error message. Does anyone have any suggestions of how to go about this? Thanks!

share|improve this question
up vote 8 down vote accepted

The UNIX shell uses glob patterns, not regular expressions. So, if you want to match file names starting with axis2 and ending with .jar, you use:

cp axis2*.jar /destination/directory
share|improve this answer
Thanks a lot! I figured it out on my own, but I didn't know about glob patterns so that's helpful and informative. – Nick Van Hoogenstyn Nov 9 '11 at 5:22

If you have GNU find and GNU cp available, you can use regular expressions as in the following command:

find . -maxdepth 1 -regextype posix-basic -regex '.*/axis2[^/]*jar$' \
       -exec cp -t ~/MyDirectory {} +

This can be handy if neither glob pattern nor bash extended glob pattern suite your needs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.