-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.

4

2 Answers 2

8

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
0

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.

11
  • 1
    ive tried that cp ../cambridge/security/parking ./parking2 it doesnt work
    – user88022
    Oct 15, 2014 at 20:49
  • 3
    @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, 2014 at 20:53
  • 3
    @user88022 because not specifying a directory means to use the current directory. It is implicit.
    – casey
    Oct 15, 2014 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, 2014 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, 2014 at 20:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.