3

I am trying to understand linux and working through some tutorials. One states that I can copy files to the current directory by using a cp -a command with a relative pathname such as

cp -a ../somedir/.   

It fails each time I run it. Is the syntax incorrect?
I tried the man page, but it didn't seem to find anything that answers my question.

  • 2
    you are missing a blank space between somedir and the last dot. See vidarlo 's answer, it is correct. Upvote it! Accept it! – Henrique Apr 15 at 20:29
  • Also something I wish I had known a whole lot earlier when learning Linux & bash is that you can press tab to get autocomplete; press it twice for suggestions. – rm-vanda Apr 15 at 20:42
6

cp -a ../somedir/. is wrong. The general syntax is

cp source target

You only specified one argument. To copy something to current directory, you can run

cp ../somedir .

Note the space before the dot. . is shorthand for current directory. .. is shorthand for parent directory.

  • +1 but I would have added how -a maintains last access stamps or something like that :) – WinEunuuchs2Unix Apr 15 at 22:55
  • -a "preserves" everything and recurses. There is a man page for this. – mckenzm Apr 16 at 1:52
0

You can say:

cp -a ../somedir . if you want to copy the folder it self with its content

Or you can say

cp -a ../somedir/* . If you want to copy the content of the folder.

the -a option will try to clone the same file structure with the same file tree to the new location

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .