Copying a source directory using the command cp -rsf when target directory exists

Clash Royale CLAN TAG#URR8PPP
up vote
-3
down vote
favorite
On Centos 7, when I use the command:
cp -rsf /path/of/source /path/of/target
When the target directory exists, files would go to /path/of/target/source.
How can I avoid that?
EDIT:
- source and target are directories.
- Symlinks meet my environment needs. I need them to be symlink in order to save storage.
For example:
mkdir /home/admin/test; mkdir /home/admin/test/1; touch /home/admin/test/1/1.txt;mkdir /home/admin/test2; mkdir /home/admin/test2/1; touch /home/admin/test2/1/1.txt;cp -rsf /home/admin/test/1 /home/admin/test2/1ls /home/admin/test2/1
result is:
drwxrwxr-x 2 admin admin 4096 Sep 16 15:57 1
-rw-rw-r-- 1 admin admin 0 Sep 16 15:56 1.txt
I wanted this result:
lrwxrwxrwx 1 admin admin 24 Sep 16 16:03 1.txt -> /home/admin/test/1/1.txt
It means the source directory itself is copied within the target, but I wanted its content to be copied (Just like when the target directory doesn't exist)
symlink cp recursive
add a comment |Â
up vote
-3
down vote
favorite
On Centos 7, when I use the command:
cp -rsf /path/of/source /path/of/target
When the target directory exists, files would go to /path/of/target/source.
How can I avoid that?
EDIT:
- source and target are directories.
- Symlinks meet my environment needs. I need them to be symlink in order to save storage.
For example:
mkdir /home/admin/test; mkdir /home/admin/test/1; touch /home/admin/test/1/1.txt;mkdir /home/admin/test2; mkdir /home/admin/test2/1; touch /home/admin/test2/1/1.txt;cp -rsf /home/admin/test/1 /home/admin/test2/1ls /home/admin/test2/1
result is:
drwxrwxr-x 2 admin admin 4096 Sep 16 15:57 1
-rw-rw-r-- 1 admin admin 0 Sep 16 15:56 1.txt
I wanted this result:
lrwxrwxrwx 1 admin admin 24 Sep 16 16:03 1.txt -> /home/admin/test/1/1.txt
It means the source directory itself is copied within the target, but I wanted its content to be copied (Just like when the target directory doesn't exist)
symlink cp recursive
how/why you want to copy from source to source?!!
â TNT
Sep 16 at 12:13
see the example. it's not source to source...
â Ali Sh
Sep 17 at 4:09
add a comment |Â
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
On Centos 7, when I use the command:
cp -rsf /path/of/source /path/of/target
When the target directory exists, files would go to /path/of/target/source.
How can I avoid that?
EDIT:
- source and target are directories.
- Symlinks meet my environment needs. I need them to be symlink in order to save storage.
For example:
mkdir /home/admin/test; mkdir /home/admin/test/1; touch /home/admin/test/1/1.txt;mkdir /home/admin/test2; mkdir /home/admin/test2/1; touch /home/admin/test2/1/1.txt;cp -rsf /home/admin/test/1 /home/admin/test2/1ls /home/admin/test2/1
result is:
drwxrwxr-x 2 admin admin 4096 Sep 16 15:57 1
-rw-rw-r-- 1 admin admin 0 Sep 16 15:56 1.txt
I wanted this result:
lrwxrwxrwx 1 admin admin 24 Sep 16 16:03 1.txt -> /home/admin/test/1/1.txt
It means the source directory itself is copied within the target, but I wanted its content to be copied (Just like when the target directory doesn't exist)
symlink cp recursive
On Centos 7, when I use the command:
cp -rsf /path/of/source /path/of/target
When the target directory exists, files would go to /path/of/target/source.
How can I avoid that?
EDIT:
- source and target are directories.
- Symlinks meet my environment needs. I need them to be symlink in order to save storage.
For example:
mkdir /home/admin/test; mkdir /home/admin/test/1; touch /home/admin/test/1/1.txt;mkdir /home/admin/test2; mkdir /home/admin/test2/1; touch /home/admin/test2/1/1.txt;cp -rsf /home/admin/test/1 /home/admin/test2/1ls /home/admin/test2/1
result is:
drwxrwxr-x 2 admin admin 4096 Sep 16 15:57 1
-rw-rw-r-- 1 admin admin 0 Sep 16 15:56 1.txt
I wanted this result:
lrwxrwxrwx 1 admin admin 24 Sep 16 16:03 1.txt -> /home/admin/test/1/1.txt
It means the source directory itself is copied within the target, but I wanted its content to be copied (Just like when the target directory doesn't exist)
symlink cp recursive
symlink cp recursive
edited Sep 16 at 11:40
asked Sep 16 at 11:06
Ali Sh
12
12
how/why you want to copy from source to source?!!
â TNT
Sep 16 at 12:13
see the example. it's not source to source...
â Ali Sh
Sep 17 at 4:09
add a comment |Â
how/why you want to copy from source to source?!!
â TNT
Sep 16 at 12:13
see the example. it's not source to source...
â Ali Sh
Sep 17 at 4:09
how/why you want to copy from source to source?!!
â TNT
Sep 16 at 12:13
how/why you want to copy from source to source?!!
â TNT
Sep 16 at 12:13
see the example. it's not source to source...
â Ali Sh
Sep 17 at 4:09
see the example. it's not source to source...
â Ali Sh
Sep 17 at 4:09
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
-3
down vote
The solution is to add -T
according to man
-T, --no-target-directory
treat DEST as a normal file
cp -rsfT /path/of/source /path/of/target
if the target directory exists it copies symlinks in it. The benefit is if there are other files in target, they remain untouched.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
-3
down vote
The solution is to add -T
according to man
-T, --no-target-directory
treat DEST as a normal file
cp -rsfT /path/of/source /path/of/target
if the target directory exists it copies symlinks in it. The benefit is if there are other files in target, they remain untouched.
add a comment |Â
up vote
-3
down vote
The solution is to add -T
according to man
-T, --no-target-directory
treat DEST as a normal file
cp -rsfT /path/of/source /path/of/target
if the target directory exists it copies symlinks in it. The benefit is if there are other files in target, they remain untouched.
add a comment |Â
up vote
-3
down vote
up vote
-3
down vote
The solution is to add -T
according to man
-T, --no-target-directory
treat DEST as a normal file
cp -rsfT /path/of/source /path/of/target
if the target directory exists it copies symlinks in it. The benefit is if there are other files in target, they remain untouched.
The solution is to add -T
according to man
-T, --no-target-directory
treat DEST as a normal file
cp -rsfT /path/of/source /path/of/target
if the target directory exists it copies symlinks in it. The benefit is if there are other files in target, they remain untouched.
edited Sep 16 at 12:05
answered Sep 16 at 11:48
Ali Sh
12
12
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469364%2fcopying-a-source-directory-using-the-command-cp-rsf-when-target-directory-exist%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
how/why you want to copy from source to source?!!
â TNT
Sep 16 at 12:13
see the example. it's not source to source...
â Ali Sh
Sep 17 at 4:09