LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-09-2009, 06:51 AM   #1
laki47
Member
 
Registered: Feb 2009
Posts: 33

Rep: Reputation: 15
Copy files which doesn not start with some prefix?


Hi,

Is there a way with cp command to copy files which doesn't start with prefix i.e. pref_?

I have the following:

temp1.txt
temp2.txt
pref_1.txt
temp3.txt
bla1.txt
bla2.txt
pref_2.txt

I want to copy all but pref_x.txt files? Can I do that with cp command?

Thank you
 
Old 07-09-2009, 08:04 AM   #2
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Code:
ls -1 | grep -v '^pref_' | xargs -i cp {} <destination_directory>
 
Old 07-09-2009, 03:31 PM   #3
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,432

Rep: Reputation: 110Reputation: 110
Code:
for i in *; do cp ${i%pref_*} directory/; done
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
difference b/w AF_ prefix and PF_ prefix related to socket Ashok_mittal Linux - Newbie 1 03-20-2008 04:15 PM
Rename files and add prefix SevenMedia Linux - Newbie 6 01-16-2008 07:04 AM
KDM on slackware 11 Doesn`t Start sanctusiuda Linux - Newbie 9 05-21-2007 11:26 PM
fedora core 2 doesn*t start on AMILO kalyanvgopal Linux - Laptop and Netbook 4 09-09-2004 11:36 PM
eth0 doesn´t start snu Linux - Networking 2 07-07-2003 10:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration