Home > OS >  copy files of all directory from specific directory to different location containing same directory
copy files of all directory from specific directory to different location containing same directory

Time:11-28

I have to cp below files to another dir which contains same dir name.

Dir Structure of abc dir:

[ab@ab abc]$ pwd
/home/ab/abc
[ab@ab abc]$ ls
dir1  dir2  README.md

I want to cp content in all dir present in /home/4px/abc and not any other files types in abcdir to/home/4px/xyzdir which contains same dir structure of abc dir.

Dir Structure of xyz dir

[ab@ab abc]$ pwd
[ab@ab xyz]$ ls
/home/ab/xyz
dir1  dir2

If dir1, dir2 already exist in xyz dir then update contents in dir.

I am using following command to fulfill the condition.

[ab@ab home]$ find /home/ab/abc -type d -name "dir*" -exec cp -r {} /home/ab/xyz \;

CodePudding user response:

I have created a source and a destination directory, and I've run following command:

Linux Prompt> cd source
Linux Prompt> find . -type d -exec mkdir /c/Temp_Folder/destination/{} \;

For your information: the switch -type d makes sure only directories are handled, so all files will be skipped.

You'll get a message, saying that . directory already exists, but all other directories/subdirectories will be created.

  • Related