Unix/Linux Go Back    

UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Expansion within cp

UNIX for Dummies Questions & Answers


Thread Tools Search this Thread Display Modes
Old Unix and Linux 12-27-2012
jawsnnn jawsnnn is offline
Join Date: May 2012
Last Activity: 7 August 2015, 4:00 PM EDT
Posts: 68
Thanks: 7
Thanked 9 Times in 9 Posts
Expansion within cp

I have a bunch of files which I need to transfer to another location... and some of these I need to skip.

For e.g. let us say the files are:


and I only want to move the first two.

I want to do something like:

cp cust_[/abc|xyz/].dat <target>

which doesn't work due to bad syntax. Is there some way of doing this without involving grep and xargs? I would like to do it with a single command if possible...
Sponsored Links
Old Unix and Linux 12-27-2012
jim mcnamara jim mcnamara is offline Forum Staff  
Join Date: Feb 2004
Last Activity: 26 October 2016, 8:53 AM EDT
Location: NM
Posts: 10,841
Thanks: 451
Thanked 972 Times in 903 Posts
Based on your pattern attempt, I assume bash if you are excluding one filename

# set extglob on -- shopt will show it's status
shopt -s extglob
cp !(def_cust).dat /somewhere

The not (!) operator means do not match. You can have multiple pipe-delimited patterns
See the section on Pattern Matching here:
Bash Reference Manual

You may want to go with another pattern/way.
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help with parameter expansion stevenswj Shell Programming and Scripting 3 10-14-2010 01:45 PM
Need to print the expansion of the found string (the expansion is beween two delimiters '-' , '||' Balaji PK Shell Programming and Scripting 9 10-28-2009 06:16 AM
sudo and expansion chebarbudo UNIX for Dummies Questions & Answers 4 01-22-2009 03:32 AM
~ expansion in printf Rledley Shell Programming and Scripting 2 11-15-2008 05:56 PM
AIX Expansion CD almuwatta AIX 0 06-23-2005 05:07 PM

All times are GMT -4. The time now is 05:08 PM.