How can I copy a file from another directory to the current one?












-3















I have this problem as part of a school assignment:



screenshot



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.










share|improve this question

























  • 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
















-3















I have this problem as part of a school assignment:



screenshot



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.










share|improve this question

























  • 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














-3












-3








-3








I have this problem as part of a school assignment:



screenshot



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.










share|improve this question
















I have this problem as part of a school assignment:



screenshot



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 11 '18 at 11:42









Volker Siegel

10.9k33260




10.9k33260










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



















  • 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










3 Answers
3






active

oldest

votes


















2














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.






share|improve this answer





















  • 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



















7














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





share|improve this answer































    -1














    I have the same assignment. how to move from stenton to oxford using relative to home pathname?






    share|improve this answer








    New contributor




    user335980 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















    • Sorry, but this is not an answer. Do neither of the existing answers help?

      – Time4Tea
      11 mins ago











    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
    });


    }
    });














    draft saved

    draft discarded


















    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

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    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.






    share|improve this answer





















    • 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
















    2














    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.






    share|improve this answer





















    • 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














    2












    2








    2







    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.






    share|improve this answer















    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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Oct 15 '14 at 20:54

























    answered Oct 15 '14 at 20:47









    ryekayoryekayo

    2,92592449




    2,92592449








    • 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





      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













    7














    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





    share|improve this answer




























      7














      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





      share|improve this answer


























        7












        7








        7







        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





        share|improve this answer













        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 16 '14 at 0:02









        PatrickPatrick

        50.5k11129180




        50.5k11129180























            -1














            I have the same assignment. how to move from stenton to oxford using relative to home pathname?






            share|improve this answer








            New contributor




            user335980 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















            • Sorry, but this is not an answer. Do neither of the existing answers help?

              – Time4Tea
              11 mins ago
















            -1














            I have the same assignment. how to move from stenton to oxford using relative to home pathname?






            share|improve this answer








            New contributor




            user335980 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















            • Sorry, but this is not an answer. Do neither of the existing answers help?

              – Time4Tea
              11 mins ago














            -1












            -1








            -1







            I have the same assignment. how to move from stenton to oxford using relative to home pathname?






            share|improve this answer








            New contributor




            user335980 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.










            I have the same assignment. how to move from stenton to oxford using relative to home pathname?







            share|improve this answer








            New contributor




            user335980 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            share|improve this answer



            share|improve this answer






            New contributor




            user335980 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            answered 18 mins ago









            user335980user335980

            1




            1




            New contributor




            user335980 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





            New contributor





            user335980 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            user335980 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.













            • Sorry, but this is not an answer. Do neither of the existing answers help?

              – Time4Tea
              11 mins ago



















            • Sorry, but this is not an answer. Do neither of the existing answers help?

              – Time4Tea
              11 mins ago

















            Sorry, but this is not an answer. Do neither of the existing answers help?

            – Time4Tea
            11 mins ago





            Sorry, but this is not an answer. Do neither of the existing answers help?

            – Time4Tea
            11 mins ago


















            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            サソリ

            広島県道265号伴広島線

            Accessing regular linux commands in Huawei's Dopra Linux