Need to copy all but three folders


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to copy all but three folders
# 1  
Old 06-23-2014
Need to copy all but three folders

Hi,

Below is the listing of folder "greece"

Code:
$ cd greece
$ ls
tmp
server
logs
properties

I wish to copy all the contents of the dir "greece" to /tmp except the below three folders and its contents under "greece"

Code:
1.logs
2.server/bin/logs
3. server/cache

I am using sh (normal C shell) or Bash only.

There are enormous files and folders under greece so the command should not consume much time.

Can you please suggest.

Last edited by mohtashims; 06-23-2014 at 03:22 PM..
# 2  
Old 06-24-2014
Quote:
Originally Posted by kekanap
cd ..
mv -rf greece /tmp/

What is this ? Please read my question .. i need to copy [not move] all contents to /tmp except the three folders within the parent greece folder.

---------- Post updated 06-24-14 at 08:13 AM ---------- Previous update was 06-23-14 at 12:25 PM ----------

bump !!

Last edited by mohtashims; 06-23-2014 at 02:36 PM..
# 3  
Old 06-24-2014
Create an exclude_file with
Code:
greece/logs
greece/server/bin/logs
greece/server/cache

And run the follwing
Code:
tar Xcf exclude_file - greece | (cd /tmp && tar tf -)

If this looks good, replace tf by xvf.
This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 06-25-2014
On AIX, you would do the reverse and have an include list:-
Code:
tar -cvf - -L include_file | (cd /tmp && tar -xvf -)

You can put files or directories in the include_file, but don't put in the top-level directory if you want to exclude certain parts. Build the include_file with something like:-
Code:
find . -type f | grep -Ev "^\./greece\/logs\/|^\.\/greece\/server\/bin\/logs\/|^\.\/greece\/server\/cache\/" > /tmp/include_file

I've been very explicit with the exclusions from the include_file to use the trailing /


Does this achieve what you want? You don't say what OS you are using, so that's why I've added this bit for AIX and others that might support -L for including rather than -X for excluding. They both have positive and negative aspects depending what you actually want to do.



Robin

---------- Post updated at 01:58 PM ---------- Previous update was at 01:56 PM ----------

PS. The sh shell is not the normal C-shell, it's the Bourne Shell. The C-shell is csh (or sometimes tcsh)

Last edited by rbatte1; 06-25-2014 at 09:56 AM.. Reason: Capilatisation
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 06-25-2014
With a recent bash, you might want to give "extended pattern matching" a try, after setting the "extglob" option:
Code:
ls server/!(cache) server/bin/!(logs) !(logs)

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

2. UNIX for Beginners Questions & Answers

Rsync added new folders after copy?

Hi guys, Don't really know much about unix or anything, just starting to mess around a little bit to have more understanding in general. So, I tried using rsync to copy my macbook pro backup/clone from an external drive I have to another external drive. I ended up using... "sudo rsync -a... (1 Reply)
Discussion started by: cbjeebs
1 Replies

3. HP-UX

Recursive copy of Folders with files

Dear All, I will appreciate any help received. Our system is running on hpux v1 My problem is as follows: We have many customer folders with name fd000100, fd000101 and so on e.g. (Testrun)(testsqa):/>ll /TESTrun/fd000100 total 48 drwxrwx--- 2 fq000100 test 96 Jun 27 2004... (17 Replies)
Discussion started by: mhbd
17 Replies

4. Shell Programming and Scripting

Copy between two different folders containing same sub-folders

I have a folder like this ls input1 dir1 dir2 dir3 file1 file2 file3 dir1, dir2 and dir3 are sub-folders inside the folder input1 ls input2 dir1 dir2 dir3 file1 file2 file3 My dir1 in input1 folder has files f1, f2, f3 and f4. My dir1 in input2 folder has file f4 and f5. ... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Copy Folders and ZIP IT

HI All I have one master folder : ABCXYZ I have sub folder in there : AB XY AZ AC PR AL Now i want to copy AB , PR ,AL in to one new folder and zip it with time stamp. like Pre_02192013_12_32.zip Zip folder should be in master folder. (2 Replies)
Discussion started by: pareshkp
2 Replies

6. Shell Programming and Scripting

ftp script to copy folders recursively

hi all I want a script that will use ftp to copy folder and sub folders from source server to current server. if i use -r switch then it just copies folders for 5 level. (1 Reply)
Discussion started by: kashif.live
1 Replies

7. Shell Programming and Scripting

Copy file to two folders with condition

Hello! Please, help me write this simple script using bash scripting. Task: In Folder1 I have files: name1.txt, name2.txt, name3.txt .. etc In Folder2 may located such files: name1.txt, name2.txt .. etc In Folder3 may located files like: name1.txt_abc{some_symbols}_vxz,... (6 Replies)
Discussion started by: optik77
6 Replies

8. Shell Programming and Scripting

Loop folders, delete files, copy new ones

Folks, I am hopeful that you may be able to help me out with writing a script that can be run nightly (as cron?) to loop through all subfolders within the "/media" directory, delete all of the files in each of them, and then copy in all of the files from the "/home//sansa" directory to each of... (6 Replies)
Discussion started by: acraig
6 Replies

9. UNIX for Dummies Questions & Answers

copy mutilple files to mutiple folders

Hi, I just started to learn shell progamming and just can't get my head around the following problem. I need to do the following: I have a folder which contains 100+ subfolders. Inside these subfolders there is one folder named 'Morph' and several jpg's. I need to copy all the files into... (4 Replies)
Discussion started by: M474746
4 Replies

10. UNIX for Advanced & Expert Users

Copy Structure excluding some folders

Hi I want to copy the structure from one place to another. -> cd /hol/; -> find . -type d | cpio -pvdm /abc/cat; while copying the structure I want to exclude some directories like test1 and Test. I have read somewhere that this can be done with -prune option. Could anyone... (2 Replies)
Discussion started by: soumodeep123
2 Replies
Login or Register to Ask a Question