LinuxQuestions.org
Register a domain and help support LQ
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, 07: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, 09: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, 04:31 PM   #3
lucmove
Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian Jessie
Posts: 715

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 05:15 PM
Rename files and add prefix SevenMedia Linux - Newbie 6 01-16-2008 08:04 AM
KDM on slackware 11 Doesn`t Start sanctusiuda Linux - Newbie 9 05-22-2007 12:26 AM
fedora core 2 doesn*t start on AMILO kalyanvgopal Linux - Laptop and Netbook 4 09-10-2004 12:36 AM
eth0 doesn´t start snu Linux - Networking 2 07-07-2003 11:58 PM


All times are GMT -5. The time now is 02:53 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration