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
.
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
.
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
cp -r path-of-child-folder/. path-of-parent-folder
to include hidden files.
Commented
May 9, 2022 at 9:00
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
.
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.
$(pwd)
stuff. After all, you're already in that directory. ..
by itself will refer to that directory's parent directory (and so on) just fine.