hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : copying certain files
Reply

Forum Jump

copying certain files

Reply Post New Thread In Hosting Security and Technology Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old
Web Hosting Master
 
Join Date: Jan 2005
Posts: 2,121

copying certain files


There is a directory with many files and subdirectories. I want to copy ALL the filesnames beginning with post-1111 to another folder. What is the command to do this?



Sponsored Links
  #2  
Old
Web Hosting Master
 
Join Date: Jan 2003
Location: U.S.A.
Posts: 3,911
Not sure exactly what your trying to do but try something like the following.

* = WildCard

Command = cp *.extension newname

**Take a Backup before attempting this method, as it will take a few tries to get it right.

  #3  
Old
Junior Guru
 
Join Date: Jun 2008
Location: Los Angeles, CA
Posts: 237
to copy from current dir to /home/new (example) the command is:
cp -rf post-1111*.* /home/new/

of course replace /home/new/ with your target directory.

__________________
www.betteresolution.com
█ Dedicated Servers & More...

Sponsored Links
  #4  
Old
Web Hosting Master
 
Join Date: Jan 2005
Posts: 2,121
How to make it copy files in subdirectories too? That command only copied files in /current/dir/ but not in /current/dir/morefiles/

Thanks.

  #5  
Old
Junior Guru Wannabe
 
Join Date: Jun 2007
Location: Spain
Posts: 37
Quote:
Originally Posted by HD Fanatic View Post
How to make it copy files in subdirectories too? That command only copied files in /current/dir/ but not in /current/dir/morefiles/
Use find.

Code:
find /current/dir/ -iname post-1111* -exec cp {} /dir/new/ \;
Regards.

  #6  
Old
Junior Guru Wannabe
 
Join Date: Jun 2007
Location: Spain
Posts: 37
Just an update,

Above command won't preserve directory tree.

I mean, if you have a file in /dir/1/post-1111test1 and another in /dir/2/post-1111test2 and copy them using find command to /dir2, you will get the following:

/dir2/post-1111test1
/dir2/post-1111test2

If you want to preserve directories... I mean:

/dir2/1/post-1111test1
/dir2/2/post-1111test2

Use the following command (you should install rsync in your server):

Code:
rsync -r --include='*/' --include='post-1111*' --exclude='*' /dir1/ /dir2/
I hope this helps.

Regards,
sahsanu

Reply

Related posts from TheWhir.com
Title Type Date Posted
The Pirate Bay Uploads Continue to Grow Despite Anti-Piracy Pressure Web Hosting News 2013-12-31 11:33:12
BitTorrent Sync Announces Platform Updates, 1M+ Users Web Hosting News 2013-11-06 13:36:26
Egnyte Synchronizes Google Drive with Private Cloud Storage Web Hosting News 2013-07-17 12:36:21
Malwarebytes Launches Data Scan-and-Backup Service Web Hosting News 2013-05-07 14:51:03
Polish Domain Registry NASK Seizes Domains Used in Pervasive Virut Botnet Web Hosting News 2013-01-21 16:56:31


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?