scp or rsync analogue for cp -T (treat target as file)
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
With cp
I can:
$ mkdir q
$ touch s
$ cp -T s q # I need same effect with scp and/or rsync.
cp: cannot overwrite directory 'q' with non-directory
$ ls q
How do I get same effect in one command with scp
and/or rsync
? I.e. When target is directory I want it to exit with non-zero exit code without actual file transfer. I don't want file s
to be placed in directory q
.
Of course, it can be checked separately. The question is how to do that in one single command. Particularly, for the sake of concurrency.
rsync scp
add a comment |Â
up vote
1
down vote
favorite
With cp
I can:
$ mkdir q
$ touch s
$ cp -T s q # I need same effect with scp and/or rsync.
cp: cannot overwrite directory 'q' with non-directory
$ ls q
How do I get same effect in one command with scp
and/or rsync
? I.e. When target is directory I want it to exit with non-zero exit code without actual file transfer. I don't want file s
to be placed in directory q
.
Of course, it can be checked separately. The question is how to do that in one single command. Particularly, for the sake of concurrency.
rsync scp
Is the issue that there does not exist a single command to do what you wish? In what ways is user DopeGhoti's answer not an acceptable solution?
â kemotep
Apr 19 at 18:08
@kemotep One command solution is simpler, faster and concurrent. His answer is not accepted because it was clearly stated that I need one command...
â George Sovetov
Apr 19 at 18:17
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
With cp
I can:
$ mkdir q
$ touch s
$ cp -T s q # I need same effect with scp and/or rsync.
cp: cannot overwrite directory 'q' with non-directory
$ ls q
How do I get same effect in one command with scp
and/or rsync
? I.e. When target is directory I want it to exit with non-zero exit code without actual file transfer. I don't want file s
to be placed in directory q
.
Of course, it can be checked separately. The question is how to do that in one single command. Particularly, for the sake of concurrency.
rsync scp
With cp
I can:
$ mkdir q
$ touch s
$ cp -T s q # I need same effect with scp and/or rsync.
cp: cannot overwrite directory 'q' with non-directory
$ ls q
How do I get same effect in one command with scp
and/or rsync
? I.e. When target is directory I want it to exit with non-zero exit code without actual file transfer. I don't want file s
to be placed in directory q
.
Of course, it can be checked separately. The question is how to do that in one single command. Particularly, for the sake of concurrency.
rsync scp
edited Apr 19 at 17:44
asked Apr 19 at 17:25
George Sovetov
1064
1064
Is the issue that there does not exist a single command to do what you wish? In what ways is user DopeGhoti's answer not an acceptable solution?
â kemotep
Apr 19 at 18:08
@kemotep One command solution is simpler, faster and concurrent. His answer is not accepted because it was clearly stated that I need one command...
â George Sovetov
Apr 19 at 18:17
add a comment |Â
Is the issue that there does not exist a single command to do what you wish? In what ways is user DopeGhoti's answer not an acceptable solution?
â kemotep
Apr 19 at 18:08
@kemotep One command solution is simpler, faster and concurrent. His answer is not accepted because it was clearly stated that I need one command...
â George Sovetov
Apr 19 at 18:17
Is the issue that there does not exist a single command to do what you wish? In what ways is user DopeGhoti's answer not an acceptable solution?
â kemotep
Apr 19 at 18:08
Is the issue that there does not exist a single command to do what you wish? In what ways is user DopeGhoti's answer not an acceptable solution?
â kemotep
Apr 19 at 18:08
@kemotep One command solution is simpler, faster and concurrent. His answer is not accepted because it was clearly stated that I need one command...
â George Sovetov
Apr 19 at 18:17
@kemotep One command solution is simpler, faster and concurrent. His answer is not accepted because it was clearly stated that I need one command...
â George Sovetov
Apr 19 at 18:17
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
This will abort if the remote directory in question exists:
if ! ssh user@host "[[ -d /path/to/directory ]]"; then
# do your scp or rsync
else
echo "Remote location is a directory. Aborting." 1&>2
exit 1
fi
If you want to make this into a one-liner, then:
ssh user@host "[[ -d /path/to/directory ]]" || <<scp or rsync>>
Currently, I'm doing similar check. I would be great if I had one command solution...
â George Sovetov
Apr 19 at 17:49
add a comment |Â
up vote
0
down vote
As an option:
ssh remote-server 'cat > /tmp/asd' < /tmp/qwe
Not a parameter though.
Example:
$ ssh localhost 'cat > /tmp/oi' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
bash: /tmp/oi: Is a directory
Transferred: sent 2832, received 2548 bytes, in 0.0 seconds
Bytes per second: sent 60414.8, received 54356.2
1
$ ssh localhost 'cat > /tmp/asd' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
Transferred: sent 2832, received 2496 bytes, in 0.0 seconds
Bytes per second: sent 62499.8, received 55084.5
0
$ ls -l /tmp/qwe,asd,oi
-rw-r--r-- 1 george george 4 Apr 19 21:21 /tmp/asd
-rw-r--r-- 1 george george 4 Apr 19 21:19 /tmp/qwe
/tmp/oi:
total 0
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
This will abort if the remote directory in question exists:
if ! ssh user@host "[[ -d /path/to/directory ]]"; then
# do your scp or rsync
else
echo "Remote location is a directory. Aborting." 1&>2
exit 1
fi
If you want to make this into a one-liner, then:
ssh user@host "[[ -d /path/to/directory ]]" || <<scp or rsync>>
Currently, I'm doing similar check. I would be great if I had one command solution...
â George Sovetov
Apr 19 at 17:49
add a comment |Â
up vote
0
down vote
This will abort if the remote directory in question exists:
if ! ssh user@host "[[ -d /path/to/directory ]]"; then
# do your scp or rsync
else
echo "Remote location is a directory. Aborting." 1&>2
exit 1
fi
If you want to make this into a one-liner, then:
ssh user@host "[[ -d /path/to/directory ]]" || <<scp or rsync>>
Currently, I'm doing similar check. I would be great if I had one command solution...
â George Sovetov
Apr 19 at 17:49
add a comment |Â
up vote
0
down vote
up vote
0
down vote
This will abort if the remote directory in question exists:
if ! ssh user@host "[[ -d /path/to/directory ]]"; then
# do your scp or rsync
else
echo "Remote location is a directory. Aborting." 1&>2
exit 1
fi
If you want to make this into a one-liner, then:
ssh user@host "[[ -d /path/to/directory ]]" || <<scp or rsync>>
This will abort if the remote directory in question exists:
if ! ssh user@host "[[ -d /path/to/directory ]]"; then
# do your scp or rsync
else
echo "Remote location is a directory. Aborting." 1&>2
exit 1
fi
If you want to make this into a one-liner, then:
ssh user@host "[[ -d /path/to/directory ]]" || <<scp or rsync>>
answered Apr 19 at 17:47
DopeGhoti
40k54779
40k54779
Currently, I'm doing similar check. I would be great if I had one command solution...
â George Sovetov
Apr 19 at 17:49
add a comment |Â
Currently, I'm doing similar check. I would be great if I had one command solution...
â George Sovetov
Apr 19 at 17:49
Currently, I'm doing similar check. I would be great if I had one command solution...
â George Sovetov
Apr 19 at 17:49
Currently, I'm doing similar check. I would be great if I had one command solution...
â George Sovetov
Apr 19 at 17:49
add a comment |Â
up vote
0
down vote
As an option:
ssh remote-server 'cat > /tmp/asd' < /tmp/qwe
Not a parameter though.
Example:
$ ssh localhost 'cat > /tmp/oi' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
bash: /tmp/oi: Is a directory
Transferred: sent 2832, received 2548 bytes, in 0.0 seconds
Bytes per second: sent 60414.8, received 54356.2
1
$ ssh localhost 'cat > /tmp/asd' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
Transferred: sent 2832, received 2496 bytes, in 0.0 seconds
Bytes per second: sent 62499.8, received 55084.5
0
$ ls -l /tmp/qwe,asd,oi
-rw-r--r-- 1 george george 4 Apr 19 21:21 /tmp/asd
-rw-r--r-- 1 george george 4 Apr 19 21:19 /tmp/qwe
/tmp/oi:
total 0
add a comment |Â
up vote
0
down vote
As an option:
ssh remote-server 'cat > /tmp/asd' < /tmp/qwe
Not a parameter though.
Example:
$ ssh localhost 'cat > /tmp/oi' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
bash: /tmp/oi: Is a directory
Transferred: sent 2832, received 2548 bytes, in 0.0 seconds
Bytes per second: sent 60414.8, received 54356.2
1
$ ssh localhost 'cat > /tmp/asd' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
Transferred: sent 2832, received 2496 bytes, in 0.0 seconds
Bytes per second: sent 62499.8, received 55084.5
0
$ ls -l /tmp/qwe,asd,oi
-rw-r--r-- 1 george george 4 Apr 19 21:21 /tmp/asd
-rw-r--r-- 1 george george 4 Apr 19 21:19 /tmp/qwe
/tmp/oi:
total 0
add a comment |Â
up vote
0
down vote
up vote
0
down vote
As an option:
ssh remote-server 'cat > /tmp/asd' < /tmp/qwe
Not a parameter though.
Example:
$ ssh localhost 'cat > /tmp/oi' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
bash: /tmp/oi: Is a directory
Transferred: sent 2832, received 2548 bytes, in 0.0 seconds
Bytes per second: sent 60414.8, received 54356.2
1
$ ssh localhost 'cat > /tmp/asd' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
Transferred: sent 2832, received 2496 bytes, in 0.0 seconds
Bytes per second: sent 62499.8, received 55084.5
0
$ ls -l /tmp/qwe,asd,oi
-rw-r--r-- 1 george george 4 Apr 19 21:21 /tmp/asd
-rw-r--r-- 1 george george 4 Apr 19 21:19 /tmp/qwe
/tmp/oi:
total 0
As an option:
ssh remote-server 'cat > /tmp/asd' < /tmp/qwe
Not a parameter though.
Example:
$ ssh localhost 'cat > /tmp/oi' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
bash: /tmp/oi: Is a directory
Transferred: sent 2832, received 2548 bytes, in 0.0 seconds
Bytes per second: sent 60414.8, received 54356.2
1
$ ssh localhost 'cat > /tmp/asd' < /tmp/qwe ; echo $?
Authenticated to localhost ([::1]:22).
Transferred: sent 2832, received 2496 bytes, in 0.0 seconds
Bytes per second: sent 62499.8, received 55084.5
0
$ ls -l /tmp/qwe,asd,oi
-rw-r--r-- 1 george george 4 Apr 19 21:21 /tmp/asd
-rw-r--r-- 1 george george 4 Apr 19 21:19 /tmp/qwe
/tmp/oi:
total 0
answered Apr 19 at 18:22
George Sovetov
1064
1064
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%2f438785%2fscp-or-rsync-analogue-for-cp-t-treat-target-as-file%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
Is the issue that there does not exist a single command to do what you wish? In what ways is user DopeGhoti's answer not an acceptable solution?
â kemotep
Apr 19 at 18:08
@kemotep One command solution is simpler, faster and concurrent. His answer is not accepted because it was clearly stated that I need one command...
â George Sovetov
Apr 19 at 18:17