redirect created files in a directory from command line

Multi tool use
I was wondering if there is any way to redirect created files from a .sh script to a specific directory without modifying the script itself but straight from command line.
Let's say:
I've a script prove.sh that creates some file in the current directory:
cat prove.sh
#! /bin/bash
echo "try 1" > try.1.txt
echo "try 2" > try.2.txt
and I would like to redirect those created files not in the current directory but in another directory (let's say ~/Documents/prove/) straight from my:
sh prove.sh <...something to redirect files to directory...>
without modifying the script itself.
Do you think is it possible?
Anyone has got a clue?
EDITED: More specifically, what I need to do is to redirect the output of a program that runs on a server and that creates various file (not stdout nothing) in a specified directory in the --out field, to another computer directly (without writing anything in the original server where the program runs).
I've only host access to this server so I can not install or sudo anything. Listening a port in the second server and redirect the output to this port in nectat did not work due to firewall in the server where the program runs that I cannot change.
Some idea?
bash shell ssh io-redirection netcat
add a comment |
I was wondering if there is any way to redirect created files from a .sh script to a specific directory without modifying the script itself but straight from command line.
Let's say:
I've a script prove.sh that creates some file in the current directory:
cat prove.sh
#! /bin/bash
echo "try 1" > try.1.txt
echo "try 2" > try.2.txt
and I would like to redirect those created files not in the current directory but in another directory (let's say ~/Documents/prove/) straight from my:
sh prove.sh <...something to redirect files to directory...>
without modifying the script itself.
Do you think is it possible?
Anyone has got a clue?
EDITED: More specifically, what I need to do is to redirect the output of a program that runs on a server and that creates various file (not stdout nothing) in a specified directory in the --out field, to another computer directly (without writing anything in the original server where the program runs).
I've only host access to this server so I can not install or sudo anything. Listening a port in the second server and redirect the output to this port in nectat did not work due to firewall in the server where the program runs that I cannot change.
Some idea?
bash shell ssh io-redirection netcat
What do you mean by in a specified directory in the --out field? Your added "EDITED" bit changes the original question quite a bit. Could you maybe combine the two so that it reads as a single uniform question?
– Kusalananda
Jan 25 at 16:13
add a comment |
I was wondering if there is any way to redirect created files from a .sh script to a specific directory without modifying the script itself but straight from command line.
Let's say:
I've a script prove.sh that creates some file in the current directory:
cat prove.sh
#! /bin/bash
echo "try 1" > try.1.txt
echo "try 2" > try.2.txt
and I would like to redirect those created files not in the current directory but in another directory (let's say ~/Documents/prove/) straight from my:
sh prove.sh <...something to redirect files to directory...>
without modifying the script itself.
Do you think is it possible?
Anyone has got a clue?
EDITED: More specifically, what I need to do is to redirect the output of a program that runs on a server and that creates various file (not stdout nothing) in a specified directory in the --out field, to another computer directly (without writing anything in the original server where the program runs).
I've only host access to this server so I can not install or sudo anything. Listening a port in the second server and redirect the output to this port in nectat did not work due to firewall in the server where the program runs that I cannot change.
Some idea?
bash shell ssh io-redirection netcat
I was wondering if there is any way to redirect created files from a .sh script to a specific directory without modifying the script itself but straight from command line.
Let's say:
I've a script prove.sh that creates some file in the current directory:
cat prove.sh
#! /bin/bash
echo "try 1" > try.1.txt
echo "try 2" > try.2.txt
and I would like to redirect those created files not in the current directory but in another directory (let's say ~/Documents/prove/) straight from my:
sh prove.sh <...something to redirect files to directory...>
without modifying the script itself.
Do you think is it possible?
Anyone has got a clue?
EDITED: More specifically, what I need to do is to redirect the output of a program that runs on a server and that creates various file (not stdout nothing) in a specified directory in the --out field, to another computer directly (without writing anything in the original server where the program runs).
I've only host access to this server so I can not install or sudo anything. Listening a port in the second server and redirect the output to this port in nectat did not work due to firewall in the server where the program runs that I cannot change.
Some idea?
bash shell ssh io-redirection netcat
bash shell ssh io-redirection netcat
edited Jan 25 at 15:59
ccc.nrc
asked Jan 25 at 14:02
ccc.nrcccc.nrc
414
414
What do you mean by in a specified directory in the --out field? Your added "EDITED" bit changes the original question quite a bit. Could you maybe combine the two so that it reads as a single uniform question?
– Kusalananda
Jan 25 at 16:13
add a comment |
What do you mean by in a specified directory in the --out field? Your added "EDITED" bit changes the original question quite a bit. Could you maybe combine the two so that it reads as a single uniform question?
– Kusalananda
Jan 25 at 16:13
What do you mean by in a specified directory in the --out field? Your added "EDITED" bit changes the original question quite a bit. Could you maybe combine the two so that it reads as a single uniform question?
– Kusalananda
Jan 25 at 16:13
What do you mean by in a specified directory in the --out field? Your added "EDITED" bit changes the original question quite a bit. Could you maybe combine the two so that it reads as a single uniform question?
– Kusalananda
Jan 25 at 16:13
add a comment |
1 Answer
1
active
oldest
votes
Assuming the script looks exactly like what you have shown:
#! /bin/bash
echo "try 1" > try.1.txt
echo "try 2" > try.2.txt
The files would be created in the current directory, regardless of what the current directory was.
Therefore, to create the files in ~/Documents/prove/
, you would be able to do
( cd ~/Documents/prove/ && bash /some/location/prove.sh )
where /some/location/prove.sh
is the pathname of the script itself.
This would cd
to the given directory first, and if that went well (the directory exists and you have permission to be there) then bash
would be invoked to run the script and the files would be created there, assuming you had permissions to create files in that directory.
I put the commands within ( ... )
, a subshell, so that the cd
would not affect the original working directory. This means that you should find yourself in the same directory where you started after executing that line.
Without the ( ... )
, you would have changed directory to ~/Documents/prove/
.
Thanks Kusalananda, but I was wondering if there is a way to call the script BEFORE and then redirect it (because I need to pipe in SSH so I have to call the script before CD)
– ccc.nrc
Jan 25 at 14:32
@ccc.nrc There is absolutely nothing preventing you from running both acd
and the script in the samessh
call. Please update your question with the requirements that you have.
– Kusalananda
Jan 25 at 15:10
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496678%2fredirect-created-files-in-a-directory-from-command-line%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Assuming the script looks exactly like what you have shown:
#! /bin/bash
echo "try 1" > try.1.txt
echo "try 2" > try.2.txt
The files would be created in the current directory, regardless of what the current directory was.
Therefore, to create the files in ~/Documents/prove/
, you would be able to do
( cd ~/Documents/prove/ && bash /some/location/prove.sh )
where /some/location/prove.sh
is the pathname of the script itself.
This would cd
to the given directory first, and if that went well (the directory exists and you have permission to be there) then bash
would be invoked to run the script and the files would be created there, assuming you had permissions to create files in that directory.
I put the commands within ( ... )
, a subshell, so that the cd
would not affect the original working directory. This means that you should find yourself in the same directory where you started after executing that line.
Without the ( ... )
, you would have changed directory to ~/Documents/prove/
.
Thanks Kusalananda, but I was wondering if there is a way to call the script BEFORE and then redirect it (because I need to pipe in SSH so I have to call the script before CD)
– ccc.nrc
Jan 25 at 14:32
@ccc.nrc There is absolutely nothing preventing you from running both acd
and the script in the samessh
call. Please update your question with the requirements that you have.
– Kusalananda
Jan 25 at 15:10
add a comment |
Assuming the script looks exactly like what you have shown:
#! /bin/bash
echo "try 1" > try.1.txt
echo "try 2" > try.2.txt
The files would be created in the current directory, regardless of what the current directory was.
Therefore, to create the files in ~/Documents/prove/
, you would be able to do
( cd ~/Documents/prove/ && bash /some/location/prove.sh )
where /some/location/prove.sh
is the pathname of the script itself.
This would cd
to the given directory first, and if that went well (the directory exists and you have permission to be there) then bash
would be invoked to run the script and the files would be created there, assuming you had permissions to create files in that directory.
I put the commands within ( ... )
, a subshell, so that the cd
would not affect the original working directory. This means that you should find yourself in the same directory where you started after executing that line.
Without the ( ... )
, you would have changed directory to ~/Documents/prove/
.
Thanks Kusalananda, but I was wondering if there is a way to call the script BEFORE and then redirect it (because I need to pipe in SSH so I have to call the script before CD)
– ccc.nrc
Jan 25 at 14:32
@ccc.nrc There is absolutely nothing preventing you from running both acd
and the script in the samessh
call. Please update your question with the requirements that you have.
– Kusalananda
Jan 25 at 15:10
add a comment |
Assuming the script looks exactly like what you have shown:
#! /bin/bash
echo "try 1" > try.1.txt
echo "try 2" > try.2.txt
The files would be created in the current directory, regardless of what the current directory was.
Therefore, to create the files in ~/Documents/prove/
, you would be able to do
( cd ~/Documents/prove/ && bash /some/location/prove.sh )
where /some/location/prove.sh
is the pathname of the script itself.
This would cd
to the given directory first, and if that went well (the directory exists and you have permission to be there) then bash
would be invoked to run the script and the files would be created there, assuming you had permissions to create files in that directory.
I put the commands within ( ... )
, a subshell, so that the cd
would not affect the original working directory. This means that you should find yourself in the same directory where you started after executing that line.
Without the ( ... )
, you would have changed directory to ~/Documents/prove/
.
Assuming the script looks exactly like what you have shown:
#! /bin/bash
echo "try 1" > try.1.txt
echo "try 2" > try.2.txt
The files would be created in the current directory, regardless of what the current directory was.
Therefore, to create the files in ~/Documents/prove/
, you would be able to do
( cd ~/Documents/prove/ && bash /some/location/prove.sh )
where /some/location/prove.sh
is the pathname of the script itself.
This would cd
to the given directory first, and if that went well (the directory exists and you have permission to be there) then bash
would be invoked to run the script and the files would be created there, assuming you had permissions to create files in that directory.
I put the commands within ( ... )
, a subshell, so that the cd
would not affect the original working directory. This means that you should find yourself in the same directory where you started after executing that line.
Without the ( ... )
, you would have changed directory to ~/Documents/prove/
.
answered Jan 25 at 14:11


KusalanandaKusalananda
128k16241398
128k16241398
Thanks Kusalananda, but I was wondering if there is a way to call the script BEFORE and then redirect it (because I need to pipe in SSH so I have to call the script before CD)
– ccc.nrc
Jan 25 at 14:32
@ccc.nrc There is absolutely nothing preventing you from running both acd
and the script in the samessh
call. Please update your question with the requirements that you have.
– Kusalananda
Jan 25 at 15:10
add a comment |
Thanks Kusalananda, but I was wondering if there is a way to call the script BEFORE and then redirect it (because I need to pipe in SSH so I have to call the script before CD)
– ccc.nrc
Jan 25 at 14:32
@ccc.nrc There is absolutely nothing preventing you from running both acd
and the script in the samessh
call. Please update your question with the requirements that you have.
– Kusalananda
Jan 25 at 15:10
Thanks Kusalananda, but I was wondering if there is a way to call the script BEFORE and then redirect it (because I need to pipe in SSH so I have to call the script before CD)
– ccc.nrc
Jan 25 at 14:32
Thanks Kusalananda, but I was wondering if there is a way to call the script BEFORE and then redirect it (because I need to pipe in SSH so I have to call the script before CD)
– ccc.nrc
Jan 25 at 14:32
@ccc.nrc There is absolutely nothing preventing you from running both a
cd
and the script in the same ssh
call. Please update your question with the requirements that you have.– Kusalananda
Jan 25 at 15:10
@ccc.nrc There is absolutely nothing preventing you from running both a
cd
and the script in the same ssh
call. Please update your question with the requirements that you have.– Kusalananda
Jan 25 at 15:10
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f496678%2fredirect-created-files-in-a-directory-from-command-line%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
hk,jMRs3V,o0dTSYf,b2s DR0fLi2yL 7ze0U,ddVLNIBZqu5eWG8nukQh0 RnOhnZkTrDDABc5NbZ5J zejytqWfKdn
What do you mean by in a specified directory in the --out field? Your added "EDITED" bit changes the original question quite a bit. Could you maybe combine the two so that it reads as a single uniform question?
– Kusalananda
Jan 25 at 16:13