How Does Cp -a Work

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

2 Answers

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest