How can I copy the contents of a child folder to its parent folder using command line?
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.
4 Answers
If you want to copy all content then run the command below
cp path-of-child-folder/* path-of-parent-folderIf particular content then run the command
cp path-of-child-folder/content path-of-parent-folder
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.
1You 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_folderNow 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.