I have this directory structure:

parent_folder/child_folder/ 

I want to copy the contents of the child folder to the parent folder, but I don't know how to do it with cp.

1

4 Answers

If you want to copy all content then run the command below

cp path-of-child-folder/* path-of-parent-folder 

If particular content then run the command

cp path-of-child-folder/content path-of-parent-folder

2

In zsh:

cp -r child/*(D) parent/ 

This covers hidden files, as well.

It's simple as that:

cp -R file_name $(pwd)/../ 

This command will copy your file, and it will print the current directory and go to the parent folder.

If you want to access the grandparent folder, you just need to add one more "../"

EXAMPLE:

To copy the file to the parent folder:

cp -R file_name $(pwd)/../ 

To copy the file to the grandparent folder:

cp -R file_name $(pwd)/../../ 

To copy the file to the great-grandparent folder :

cp -R file_name $(pwd)/../../../ 

etc.

1

You can use this simple sequence of commands (assuming that parent_folder is an absolute path):

cd parent_folder cp -R child_folder/* . 

The second command is the essential one.
And if you want to remove the child_folder after the copy procedure, use

rm -R child_folder 

Now your parent_folder contains both the contents of itself plus the contents of child_folder.

Note that this doesn't flatten the directory structure on the child_folder.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy