How does cp -a work
Solution 1
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.
Solution 2
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
Related videos on Youtube
NodeNewb
Updated on September 18, 2022Comments
-
NodeNewb almost 2 years
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 ascp -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.-
Henrique about 5 yearsyou are missing a blank space between somedir and the last dot. See vidarlo 's answer, it is correct. Upvote it! Accept it!
-
rm-vanda about 5 yearsAlso 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.
-
-
mckenzm about 5 years-a "preserves" everything and recurses. There is a man page for this.