cancel
Showing results for 
Search instead for 
Did you mean: 
jeesshnasree
Starfighter Starfighter
Starfighter
  • 87 Views

how to copy folders in linux but exclude some folders

Hello All ,

 

 

I have one query :

Operating System : Linux OS

Activity : Copy multiple folders with * but exclude some folders during copy from source path to destination path . 

 

Scenario :

In this path "/tmp/abc/"

folders list 

def

ghi

jkl

mno

xyz 

while using "cp -r *  /tmp/test-path" but exclude "mno" folder .

if possible any command exclude command while using 'cp' copy command then please provide command & example .

 

I am waiting for your valuable help .

I hope you understand my query & scenario .

 

Thank you ,

Jeesshnasree

Labels (1)
0 Kudos
2 Replies
DavidOBrien
Starfighter Starfighter
Starfighter
  • 74 Views

I don't think you can do this with `cp` but `rsync` should do it. Something like:
`rsync -a --exclude=/dir/to/ignore /path/to/copy /path/to/destination`

`-a` copies recursively and preserves file attributes. You can add `-v` to get more verbose output.

Have a look at `man rsync` for more details.

NB: I haven't tested this specific command so try it out on a test dir first.

Hope this helps.

 

Gopinath_Pigili
Flight Engineer
Flight Engineer
  • 66 Views

If you want to copy a directory but exclude certain files or directories within it, you can use the rsync command with the –exclude option...! Here is the sample command:

rsync -av --exclude 'dir1' sourcedir/ destinationdir/

Thanks

 

0 Kudos
Join the discussion
You must log in to join this conversation.