Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 26, 2006, 01:11 PM   #1
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Unix copy directory but skip files

Anyone know of a unix command to copy a directory, but skip certain files? Kind of like the -x argument for zip. I looked at man cp and man ditto but didn't see any such option. Basically I'm writing a Bash script that automates copying a directory out of a Subversion repository, and I want to strip all the *.svn* files from it.
kainjow is offline   0 Reply With Quote
Old Sep 26, 2006, 01:19 PM   #2
bousozoku
Moderator emeritus
 
Join Date: Jun 2002
Location: Gone but not forgotten.
Use awk or grep to filter them and use the filtered output to copy the rest.
bousozoku is offline   0 Reply With Quote
Old Sep 26, 2006, 01:56 PM   #3
lexfuzo
macrumors 6502
 
Join Date: Mar 2005
Location: The heart of Europe
rsync

$ man rsync | grep exclude
o exclude and exclude-from options similar to GNU tar
o a CVS exclude mode for ignoring the same files that CVS would
rsync -avuzb --exclude ’*~’ samba:samba/ .
--delete-excluded also delete excluded files on receiver
-C, --cvs-exclude auto-ignore files in the same way CVS does
--exclude=PATTERN exclude files matching PATTERN
--exclude-from=FILE read exclude patterns from FILE
--include=PATTERN don’t exclude files matching PATTERN

...
__________________
Proud owner of an iBook 12/1.33
Soon upgrading to a MacBook Con
lexfuzo is offline   0 Reply With Quote
Old Sep 26, 2006, 02:02 PM   #4
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
find would also be pretty easy to make this work.

something like cp `find . -not -name "*.svn"` destination/ (not tested)

You could add in xargs if there are lots of files in the source directory...

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Sep 26, 2006, 04:57 PM   #5
savar
macrumors 68000
 
savar's Avatar
 
Join Date: Jun 2003
Location: District of Columbia
Send a message via AIM to savar
Quote:
Originally Posted by kainjow
Anyone know of a unix command to copy a directory, but skip certain files? Kind of like the -x argument for zip. I looked at man cp and man ditto but didn't see any such option. Basically I'm writing a Bash script that automates copying a directory out of a Subversion repository, and I want to strip all the *.svn* files from it.
find ./ -type d | xargs -i cp {} dest_dir

What do I win?

Oh wait, you only want to skip *some* files, not all of them. Okay:

find ./ ! -name '*.svn' | xargs -i cp {} dest_dir
__________________
Mehce
savar is offline   0 Reply With Quote
Old Sep 26, 2006, 07:30 PM   #6
kainjow
Thread Starter
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Thanks guys, plenty of solutions.

I ended up just removing the files after I copied them, because I'm lazy

Code:
find directory -name "*.svn*" -exec rm -rf {} \;
kainjow is offline   0 Reply With Quote
Old Sep 26, 2006, 10:42 PM   #7
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by kainjow
Thanks guys, plenty of solutions.
So many ways to skin a cat....

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Nov 24, 2006, 06:13 PM   #8
mrkenzie
macrumors newbie
 
Join Date: Nov 2006
I too am trying to copy files over and exclude certain files/directories. When I use the following code:

Code:
find ./ ! -name '*.svn' | xargs -i cp {} dest_dir
it works except if it needs to copy a new empty directory. So basically I am trying to synchronize to directories and it is working except for the case where there is an empty directory.

Anyone know how to get it to work including with empty directories?

Thanks.
mrkenzie is offline   0 Reply With Quote
Old Nov 24, 2006, 06:19 PM   #9
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by mrkenzie View Post
I too am trying to copy files over and exclude certain files/directories. When I use the following code:

Code:
find ./ ! -name '*.svn' | xargs -i cp {} dest_dir
it works except if it needs to copy a new empty directory. So basically I am trying to synchronize to directories and it is working except for the case where there is an empty directory.

Anyone know how to get it to work including with empty directories?

Thanks.
I think it's a limitation of cp. You could try and just do it in two steps. Copy the directory structure with a
Code:
find ./ -type d ... |mkdir
first?

Or, use a tool better suited towards syncing, like rsync.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
copy a directory using bash - how to do it? error: is a directory (not copied). cupboy1 OS X 10.8 Mountain Lion 0 Mar 23, 2014 09:50 PM
Help me delete some files in mac's unix cool11 OS X 9 Mar 5, 2014 06:20 PM
Copy files into sub-directory in list view theEconomist Mac Basics and Help 0 Jul 4, 2013 04:20 AM
Creating Unix Executable Files Chuck3663 Windows, Linux & Others on the Mac 0 Jun 19, 2013 01:16 PM
MP4 files that skip? JMEANS Apple TV and Home Theater 15 Jun 7, 2013 04:26 PM

Forum Jump

All times are GMT -5. The time now is 10:14 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC