Operating System - Linux
1827783 Members
2581 Online
109969 Solutions
New Discussion

Re: copy sub directories except specific directory

 
SOLVED
Go to solution
file system
Frequent Advisor

copy sub directories except specific directory

Hi all
I usually copy many files in directories.
but I m going to copy that excep for 1 directory.

How can I get the command like that.

==================
dev
drwxr-xr-x 11 root sys 512 9¿ù 26ÀÏ 15:16 devices
drwxr-xr-x 61 root sys 4096 1¿ù 3ÀÏ 17:15 etc
drwxr-xr-x 2 root sys 512 7¿ù 27ÀÏ 20:37 export
dr-xr-xr-x 1 root root 1 12¿ù 27ÀÏ 10:24 home
drwxr-xr-x 10 root sys 512 7¿ù 27ÀÏ 23:13 kernel
drwxr-xr-x 3 root other 512 10¿ù 10ÀÏ 12:12 kwon
==================
I 'm going to copy sub directories except kwon directory.

To notice that so many files in NAS and consider performance first.

If you have an idea additional to fit that,
Post it and reply me , thank you in advance.
3 REPLIES 3
Alexander Chuzhoy
Honored Contributor
Solution

Re: copy sub directories except specific directory

This is pretty simple with the "rsync" tool. Use rsync with "--exclude" option.
See man rsync for more details.
Cédric MELLON
Honored Contributor

Re: copy sub directories except specific directory

Hi,
This should work for you:

for rep in `ls ./source/ | grep -v kwon`
do
cp -R ./source/$rep /tmp/target/
done

=> for rep in `ls ./source/ | grep -v kwon`^Jdo^Jcp -R ./source/$rep /tmp/target/^Jdone

Good luck,
Cedric.
wooot wooot wooot !!!
Frank de Vries
Respected Contributor

Re: copy sub directories except specific directory

Assuming you want to avoid to copy
the current directory,

you could use a for loop and filter out
in this loop the kwon

for dirlist in $(ls -1p | grep "[a-z][a-z]*" | grep "/" | grep -v kwon)

do

cp $dirlist $target

done

Anyway
There are more ways to do it.



Look before you leap