How can I copy a file from another directory to the current one?
I have this problem as part of a school assignment:
NOTE: In case it's hard to read in the image above, here's the directory tree:
$ tree
.
`-- sample_dir1
`-- sample_dir
|-- admin
|-- cambridge
| |-- cafeteria
| |-- library
| `-- security
| |-- annex
| |-- building
| `-- parking
|-- faculty
|-- history.exe
|-- markham
| |-- annex
| |-- building1
| `-- parking
|-- oxford
| |-- outline.doc
| |-- programming
| | `-- report.pdf
| `-- security
`-- stenton
|-- gen_ed
`-- lib_arts
|-- english.txt
`-- match.doc
15 directories, 11 files
I tried doing the command:
$ cp ../cambridge/security/parking ./parking2
...but it isn't working. The question in the image above states that the current directory is stenton
, and that we need to make a copy of the file named parking
(from the security
directory), and to name the new file parking2, and place it in the current directory,
stenton`, using relative pathnames.
What am I doing wrong? My cp
command seems to be correct.
cp
add a comment |
I have this problem as part of a school assignment:
NOTE: In case it's hard to read in the image above, here's the directory tree:
$ tree
.
`-- sample_dir1
`-- sample_dir
|-- admin
|-- cambridge
| |-- cafeteria
| |-- library
| `-- security
| |-- annex
| |-- building
| `-- parking
|-- faculty
|-- history.exe
|-- markham
| |-- annex
| |-- building1
| `-- parking
|-- oxford
| |-- outline.doc
| |-- programming
| | `-- report.pdf
| `-- security
`-- stenton
|-- gen_ed
`-- lib_arts
|-- english.txt
`-- match.doc
15 directories, 11 files
I tried doing the command:
$ cp ../cambridge/security/parking ./parking2
...but it isn't working. The question in the image above states that the current directory is stenton
, and that we need to make a copy of the file named parking
(from the security
directory), and to name the new file parking2, and place it in the current directory,
stenton`, using relative pathnames.
What am I doing wrong? My cp
command seems to be correct.
cp
yes an assignment ^^ stuck on this questions for 1 day now
– user88022
Oct 15 '14 at 20:46
man7.org/linux/man-pages/man1/cp.1.html
– casey
Oct 15 '14 at 20:47
2
@user88022 Sorry for the rough introduction you got here. Not knowing about embedding images is understandable for a new user, but you should explain what you've tried (and how it failed) when asking for help.
– Patrick
Oct 15 '14 at 23:43
2
This is ULI101 at Seneca College, which we get year after year. All assignments "MUST consist of the student’s OWN work".
– JdeBP
Oct 22 '16 at 1:52
add a comment |
I have this problem as part of a school assignment:
NOTE: In case it's hard to read in the image above, here's the directory tree:
$ tree
.
`-- sample_dir1
`-- sample_dir
|-- admin
|-- cambridge
| |-- cafeteria
| |-- library
| `-- security
| |-- annex
| |-- building
| `-- parking
|-- faculty
|-- history.exe
|-- markham
| |-- annex
| |-- building1
| `-- parking
|-- oxford
| |-- outline.doc
| |-- programming
| | `-- report.pdf
| `-- security
`-- stenton
|-- gen_ed
`-- lib_arts
|-- english.txt
`-- match.doc
15 directories, 11 files
I tried doing the command:
$ cp ../cambridge/security/parking ./parking2
...but it isn't working. The question in the image above states that the current directory is stenton
, and that we need to make a copy of the file named parking
(from the security
directory), and to name the new file parking2, and place it in the current directory,
stenton`, using relative pathnames.
What am I doing wrong? My cp
command seems to be correct.
cp
I have this problem as part of a school assignment:
NOTE: In case it's hard to read in the image above, here's the directory tree:
$ tree
.
`-- sample_dir1
`-- sample_dir
|-- admin
|-- cambridge
| |-- cafeteria
| |-- library
| `-- security
| |-- annex
| |-- building
| `-- parking
|-- faculty
|-- history.exe
|-- markham
| |-- annex
| |-- building1
| `-- parking
|-- oxford
| |-- outline.doc
| |-- programming
| | `-- report.pdf
| `-- security
`-- stenton
|-- gen_ed
`-- lib_arts
|-- english.txt
`-- match.doc
15 directories, 11 files
I tried doing the command:
$ cp ../cambridge/security/parking ./parking2
...but it isn't working. The question in the image above states that the current directory is stenton
, and that we need to make a copy of the file named parking
(from the security
directory), and to name the new file parking2, and place it in the current directory,
stenton`, using relative pathnames.
What am I doing wrong? My cp
command seems to be correct.
cp
cp
edited Jul 11 '18 at 11:42
Volker Siegel
11k33260
11k33260
asked Oct 15 '14 at 20:41
user88022user88022
16113
16113
yes an assignment ^^ stuck on this questions for 1 day now
– user88022
Oct 15 '14 at 20:46
man7.org/linux/man-pages/man1/cp.1.html
– casey
Oct 15 '14 at 20:47
2
@user88022 Sorry for the rough introduction you got here. Not knowing about embedding images is understandable for a new user, but you should explain what you've tried (and how it failed) when asking for help.
– Patrick
Oct 15 '14 at 23:43
2
This is ULI101 at Seneca College, which we get year after year. All assignments "MUST consist of the student’s OWN work".
– JdeBP
Oct 22 '16 at 1:52
add a comment |
yes an assignment ^^ stuck on this questions for 1 day now
– user88022
Oct 15 '14 at 20:46
man7.org/linux/man-pages/man1/cp.1.html
– casey
Oct 15 '14 at 20:47
2
@user88022 Sorry for the rough introduction you got here. Not knowing about embedding images is understandable for a new user, but you should explain what you've tried (and how it failed) when asking for help.
– Patrick
Oct 15 '14 at 23:43
2
This is ULI101 at Seneca College, which we get year after year. All assignments "MUST consist of the student’s OWN work".
– JdeBP
Oct 22 '16 at 1:52
yes an assignment ^^ stuck on this questions for 1 day now
– user88022
Oct 15 '14 at 20:46
yes an assignment ^^ stuck on this questions for 1 day now
– user88022
Oct 15 '14 at 20:46
man7.org/linux/man-pages/man1/cp.1.html
– casey
Oct 15 '14 at 20:47
man7.org/linux/man-pages/man1/cp.1.html
– casey
Oct 15 '14 at 20:47
2
2
@user88022 Sorry for the rough introduction you got here. Not knowing about embedding images is understandable for a new user, but you should explain what you've tried (and how it failed) when asking for help.
– Patrick
Oct 15 '14 at 23:43
@user88022 Sorry for the rough introduction you got here. Not knowing about embedding images is understandable for a new user, but you should explain what you've tried (and how it failed) when asking for help.
– Patrick
Oct 15 '14 at 23:43
2
2
This is ULI101 at Seneca College, which we get year after year. All assignments "MUST consist of the student’s OWN work".
– JdeBP
Oct 22 '16 at 1:52
This is ULI101 at Seneca College, which we get year after year. All assignments "MUST consist of the student’s OWN work".
– JdeBP
Oct 22 '16 at 1:52
add a comment |
2 Answers
2
active
oldest
votes
This is a very elementary question. I would read up on the man pages for this one. But nonetheless, here is your answer:
cp <SOURCE> .
For example:
I have a file in this directory: /home/rkah/sample1
The file is called: sample
Say if I wanted to go to my home directory which is: /home/rkah/
and copy sample
to /home/rkah/
, I would run this command:
cp ~/sample/sample .
The .
symbol stands for present working directory or the directory im currently in.
1
ive tried that cp ../cambridge/security/parking ./parking2 it doesnt work
– user88022
Oct 15 '14 at 20:49
2
@user88022 that command should work, but your software testing you may be sensitive to./parking2
since a relative path isn't required to reference the current directory.
– casey
Oct 15 '14 at 20:53
2
@user88022 because not specifying a directory means to use the current directory. It is implicit.
– casey
Oct 15 '14 at 20:56
3
@ryekayo he had to copy a file from location1 to location2 with a new name, his first command was right, but he is not in a real shell but a testing software that wants a very specific answer and did not need the./
to reference the current directory for his destination filename.
– casey
Oct 15 '14 at 20:57
3
@ryekayo its ok, but realize that his first command you claim is wrong is completely valid for what he wants to do if he were in a real shell. You misread the question (reading the title and not the actual problem within the image he posted).
– casey
Oct 15 '14 at 20:59
|
show 6 more comments
The problem you're running into seems to be with your homework program.
From your comment on the other answer, you tried:
cp ../cambridge/security/parking ./parking2
This is a perfectly valid command in a normal shell. However the issue is likely that your testing program doesn't want the ./
on the ./parking2
.
When specifying the path to a file (with virtually any program, not just cp
), if there is no leading /
on the path, it implicitly becomes ./
. So you should be good if you change your command to:
cp ../cambridge/security/parking parking2
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%2f162354%2fhow-can-i-copy-a-file-from-another-directory-to-the-current-one%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is a very elementary question. I would read up on the man pages for this one. But nonetheless, here is your answer:
cp <SOURCE> .
For example:
I have a file in this directory: /home/rkah/sample1
The file is called: sample
Say if I wanted to go to my home directory which is: /home/rkah/
and copy sample
to /home/rkah/
, I would run this command:
cp ~/sample/sample .
The .
symbol stands for present working directory or the directory im currently in.
1
ive tried that cp ../cambridge/security/parking ./parking2 it doesnt work
– user88022
Oct 15 '14 at 20:49
2
@user88022 that command should work, but your software testing you may be sensitive to./parking2
since a relative path isn't required to reference the current directory.
– casey
Oct 15 '14 at 20:53
2
@user88022 because not specifying a directory means to use the current directory. It is implicit.
– casey
Oct 15 '14 at 20:56
3
@ryekayo he had to copy a file from location1 to location2 with a new name, his first command was right, but he is not in a real shell but a testing software that wants a very specific answer and did not need the./
to reference the current directory for his destination filename.
– casey
Oct 15 '14 at 20:57
3
@ryekayo its ok, but realize that his first command you claim is wrong is completely valid for what he wants to do if he were in a real shell. You misread the question (reading the title and not the actual problem within the image he posted).
– casey
Oct 15 '14 at 20:59
|
show 6 more comments
This is a very elementary question. I would read up on the man pages for this one. But nonetheless, here is your answer:
cp <SOURCE> .
For example:
I have a file in this directory: /home/rkah/sample1
The file is called: sample
Say if I wanted to go to my home directory which is: /home/rkah/
and copy sample
to /home/rkah/
, I would run this command:
cp ~/sample/sample .
The .
symbol stands for present working directory or the directory im currently in.
1
ive tried that cp ../cambridge/security/parking ./parking2 it doesnt work
– user88022
Oct 15 '14 at 20:49
2
@user88022 that command should work, but your software testing you may be sensitive to./parking2
since a relative path isn't required to reference the current directory.
– casey
Oct 15 '14 at 20:53
2
@user88022 because not specifying a directory means to use the current directory. It is implicit.
– casey
Oct 15 '14 at 20:56
3
@ryekayo he had to copy a file from location1 to location2 with a new name, his first command was right, but he is not in a real shell but a testing software that wants a very specific answer and did not need the./
to reference the current directory for his destination filename.
– casey
Oct 15 '14 at 20:57
3
@ryekayo its ok, but realize that his first command you claim is wrong is completely valid for what he wants to do if he were in a real shell. You misread the question (reading the title and not the actual problem within the image he posted).
– casey
Oct 15 '14 at 20:59
|
show 6 more comments
This is a very elementary question. I would read up on the man pages for this one. But nonetheless, here is your answer:
cp <SOURCE> .
For example:
I have a file in this directory: /home/rkah/sample1
The file is called: sample
Say if I wanted to go to my home directory which is: /home/rkah/
and copy sample
to /home/rkah/
, I would run this command:
cp ~/sample/sample .
The .
symbol stands for present working directory or the directory im currently in.
This is a very elementary question. I would read up on the man pages for this one. But nonetheless, here is your answer:
cp <SOURCE> .
For example:
I have a file in this directory: /home/rkah/sample1
The file is called: sample
Say if I wanted to go to my home directory which is: /home/rkah/
and copy sample
to /home/rkah/
, I would run this command:
cp ~/sample/sample .
The .
symbol stands for present working directory or the directory im currently in.
edited Oct 15 '14 at 20:54
answered Oct 15 '14 at 20:47
ryekayoryekayo
2,96892449
2,96892449
1
ive tried that cp ../cambridge/security/parking ./parking2 it doesnt work
– user88022
Oct 15 '14 at 20:49
2
@user88022 that command should work, but your software testing you may be sensitive to./parking2
since a relative path isn't required to reference the current directory.
– casey
Oct 15 '14 at 20:53
2
@user88022 because not specifying a directory means to use the current directory. It is implicit.
– casey
Oct 15 '14 at 20:56
3
@ryekayo he had to copy a file from location1 to location2 with a new name, his first command was right, but he is not in a real shell but a testing software that wants a very specific answer and did not need the./
to reference the current directory for his destination filename.
– casey
Oct 15 '14 at 20:57
3
@ryekayo its ok, but realize that his first command you claim is wrong is completely valid for what he wants to do if he were in a real shell. You misread the question (reading the title and not the actual problem within the image he posted).
– casey
Oct 15 '14 at 20:59
|
show 6 more comments
1
ive tried that cp ../cambridge/security/parking ./parking2 it doesnt work
– user88022
Oct 15 '14 at 20:49
2
@user88022 that command should work, but your software testing you may be sensitive to./parking2
since a relative path isn't required to reference the current directory.
– casey
Oct 15 '14 at 20:53
2
@user88022 because not specifying a directory means to use the current directory. It is implicit.
– casey
Oct 15 '14 at 20:56
3
@ryekayo he had to copy a file from location1 to location2 with a new name, his first command was right, but he is not in a real shell but a testing software that wants a very specific answer and did not need the./
to reference the current directory for his destination filename.
– casey
Oct 15 '14 at 20:57
3
@ryekayo its ok, but realize that his first command you claim is wrong is completely valid for what he wants to do if he were in a real shell. You misread the question (reading the title and not the actual problem within the image he posted).
– casey
Oct 15 '14 at 20:59
1
1
ive tried that cp ../cambridge/security/parking ./parking2 it doesnt work
– user88022
Oct 15 '14 at 20:49
ive tried that cp ../cambridge/security/parking ./parking2 it doesnt work
– user88022
Oct 15 '14 at 20:49
2
2
@user88022 that command should work, but your software testing you may be sensitive to
./parking2
since a relative path isn't required to reference the current directory.– casey
Oct 15 '14 at 20:53
@user88022 that command should work, but your software testing you may be sensitive to
./parking2
since a relative path isn't required to reference the current directory.– casey
Oct 15 '14 at 20:53
2
2
@user88022 because not specifying a directory means to use the current directory. It is implicit.
– casey
Oct 15 '14 at 20:56
@user88022 because not specifying a directory means to use the current directory. It is implicit.
– casey
Oct 15 '14 at 20:56
3
3
@ryekayo he had to copy a file from location1 to location2 with a new name, his first command was right, but he is not in a real shell but a testing software that wants a very specific answer and did not need the
./
to reference the current directory for his destination filename.– casey
Oct 15 '14 at 20:57
@ryekayo he had to copy a file from location1 to location2 with a new name, his first command was right, but he is not in a real shell but a testing software that wants a very specific answer and did not need the
./
to reference the current directory for his destination filename.– casey
Oct 15 '14 at 20:57
3
3
@ryekayo its ok, but realize that his first command you claim is wrong is completely valid for what he wants to do if he were in a real shell. You misread the question (reading the title and not the actual problem within the image he posted).
– casey
Oct 15 '14 at 20:59
@ryekayo its ok, but realize that his first command you claim is wrong is completely valid for what he wants to do if he were in a real shell. You misread the question (reading the title and not the actual problem within the image he posted).
– casey
Oct 15 '14 at 20:59
|
show 6 more comments
The problem you're running into seems to be with your homework program.
From your comment on the other answer, you tried:
cp ../cambridge/security/parking ./parking2
This is a perfectly valid command in a normal shell. However the issue is likely that your testing program doesn't want the ./
on the ./parking2
.
When specifying the path to a file (with virtually any program, not just cp
), if there is no leading /
on the path, it implicitly becomes ./
. So you should be good if you change your command to:
cp ../cambridge/security/parking parking2
add a comment |
The problem you're running into seems to be with your homework program.
From your comment on the other answer, you tried:
cp ../cambridge/security/parking ./parking2
This is a perfectly valid command in a normal shell. However the issue is likely that your testing program doesn't want the ./
on the ./parking2
.
When specifying the path to a file (with virtually any program, not just cp
), if there is no leading /
on the path, it implicitly becomes ./
. So you should be good if you change your command to:
cp ../cambridge/security/parking parking2
add a comment |
The problem you're running into seems to be with your homework program.
From your comment on the other answer, you tried:
cp ../cambridge/security/parking ./parking2
This is a perfectly valid command in a normal shell. However the issue is likely that your testing program doesn't want the ./
on the ./parking2
.
When specifying the path to a file (with virtually any program, not just cp
), if there is no leading /
on the path, it implicitly becomes ./
. So you should be good if you change your command to:
cp ../cambridge/security/parking parking2
The problem you're running into seems to be with your homework program.
From your comment on the other answer, you tried:
cp ../cambridge/security/parking ./parking2
This is a perfectly valid command in a normal shell. However the issue is likely that your testing program doesn't want the ./
on the ./parking2
.
When specifying the path to a file (with virtually any program, not just cp
), if there is no leading /
on the path, it implicitly becomes ./
. So you should be good if you change your command to:
cp ../cambridge/security/parking parking2
answered Oct 16 '14 at 0:02
PatrickPatrick
50.7k11131181
50.7k11131181
add a comment |
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%2f162354%2fhow-can-i-copy-a-file-from-another-directory-to-the-current-one%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
yes an assignment ^^ stuck on this questions for 1 day now
– user88022
Oct 15 '14 at 20:46
man7.org/linux/man-pages/man1/cp.1.html
– casey
Oct 15 '14 at 20:47
2
@user88022 Sorry for the rough introduction you got here. Not knowing about embedding images is understandable for a new user, but you should explain what you've tried (and how it failed) when asking for help.
– Patrick
Oct 15 '14 at 23:43
2
This is ULI101 at Seneca College, which we get year after year. All assignments "MUST consist of the student’s OWN work".
– JdeBP
Oct 22 '16 at 1:52