Results 1 to 6 of 6
Thread: copying certain files
Hybrid View
-
05-20-2009, 03:47 PM #1Web Hosting Master
- Join Date
- Jan 2005
- Posts
- 2,203
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?
-
05-20-2009, 06:56 PM #2Web Hosting Master
- Join Date
- Jan 2003
- Location
- U.S.A.
- Posts
- 3,928
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.
-
05-20-2009, 08:44 PM #3Web Hosting Guru
- Join Date
- Jun 2008
- Location
- Los Angeles, CA
- Posts
- 272
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.█ Lebnene
█ Consultant: Colocation, Cloud & Dedicated Servers
-
05-20-2009, 10:37 PM #4Web Hosting Master
- Join Date
- Jan 2005
- Posts
- 2,203
How to make it copy files in subdirectories too? That command only copied files in /current/dir/ but not in /current/dir/morefiles/
Thanks.
-
05-20-2009, 11:04 PM #5Junior Guru Wannabe
- Join Date
- Jun 2007
- Location
- Spain
- Posts
- 37
-
05-21-2009, 12:37 AM #6Junior 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/
Regards,
sahsanu