[Omaha.pm] find a -d 1 -type d -exec cp -R {} b/ \;

Jay Hannah jhannah at mutationgrid.com
Thu Feb 10 10:08:59 PST 2011


GNU++   Total elapsed time:  17 minutes   :)

Jay Hannah
Software Architect
jhannah at mutationgrid.com | http://mutationgrid.com | 1-402-598-7782





17:51 < kiran-mac> any one- given a parentDirectory containing multiple folders and files, How could I 
                   copy the parentDirectory with only folders and the content inside of that folder 
                   and leave behind all the files?
17:52 < kiran-mac> up to now I have been copying only the parentDirectory. Since the files are huge I 
                   want to exclude them during copying to my folder 
17:53 < jhannah> sounds like a 10 line Perl program to me
17:53 < jhannah> "recreate this directory tree, but none of the files" 
17:53 < jhannah> ?
17:54 < kiran-mac> yes
17:55 < kiran-mac> non of the files in the parentDirectory but I want the files inside of the folders
17:55 < jhannah> inside of all of all of the folders recursively?
17:55 < kiran-mac> yes
17:56 < kiran-mac> currently the way I have it set up is
18:05 < jhannah> find a -d 1 -type d -exec cp -R {} b/ \;
18:05 < jhannah> substitute a for whatever your source directory is and b for whatever your target 
                 directory is



The little Perl program I started writing then realized I didn't need....

$ cat copy_deep_except_topdir_files.pl 
my $source_dir = $ARGV[0];
my $target_dir = $ARGV[1];

die unless (-d $source_dir);

die if (-d $target_dir);
mkdir $target_dir or die;

my @files = glob("$source_dir/*");
foreach my $file (@files) {
   if (-d $file) {
      my $cmd = "cp -R $source_dir/$
   
}




More information about the Omaha-pm mailing list