Regular Expression – Using Regular Expressions with cp

cpregular expression

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!

Best Answer

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
Related Question