cp command won't work on terminal

I have typed the following:

cp ~/Documents/"Tidy room".key ~/Documents/"maths g&t"

cp: /Users/Jasper/Documents/Tidy room.key is a directory (not copied).

Please help me

Mac mini

Posted on Apr 16, 2014 5:07 AM

Reply
15 replies

Apr 16, 2014 6:08 AM in response to repaj

From the man page for cp:


-R If source_file designates a directory, cp copies the directory and the entire subtree connected
at that point. If the source_file ends in a /, the contents of the directory are copied rather
than the directory itself. This option also causes symbolic links to be copied, rather than
indirected through, and for cp to create special files rather than copying them as normal files.
Created directories have the same mode as the corresponding source directory, unmodified by the
process' umask.
In -R mode, cp will continue copying even if errors are detected.
Note that cp copies hard-linked files as separate files. If you need to preserve hard links,
consider using tar(1), cpio(1), or pax(1) instead.

Apr 16, 2014 10:24 PM in response to repaj

no bother 🙂 whenever trying to learn these things, creating and playing with simple folders & files helps


scenario: my current directory is ~/Working, create the experimental folders and file:


mml:Working chris$ mkdir testdir1

mml:Working chris$ ls

testdir1

mml:Working chris$ mkdir testdir2

mml:Working chris$ ls

testdir1 testdir2

mml:Working chris$ echo 'test text' > testdir1/filea.txt

mml:Working chris$ cd testdir1

mml:testdir1 chris$ ls

filea.txt

mml:testdir1 chris$ cat filea.txt

test text


So now the file is in testdir1, with some text in it.


Move only:


mml:testdir1 chris$ mv filea.txt ../testdir2

mml:testdir1 chris$ ls

mml:testdir1 chris$ ls ../testdir2

filea.txt


So filea.txt has been moved to testdir2.


Rename only:


mml:testdir1 chris$ cd ../testdir2

mml:testdir2 chris$ ls

filea.txt

mml:testdir2 chris$ mv filea.txt fileb.txt

mml:testdir2 chris$ ls

fileb.txt

mml:testdir2 chris$ cat fileb.txt

test text


So filea.txt has been renamed to fileb.txt (really, filea.txt was copied to fileb.txt (a new file) and filea.txt was deleted behind)


Move and rename:


mml:testdir2 chris$ ls

fileb.txt

mml:testdir2 chris$ mv fileb.txt ../testdir1/filea.txt

mml:testdir2 chris$ ls

mml:testdir2 chris$ cd ../testdir1

mml:testdir1 chris$ ls

filea.txt

mml:testdir1 chris$ cat filea.txt

test text


So again, fileb.txt was copied into testdir1 as "filea.txt" and fileb.txt was deleted behind. What can trip people up is that you need write permission for both the source and destination directories (destination to copy into, source to delete behind). 🙂

Apr 17, 2014 6:36 AM in response to repaj

mv at its simplest level, removes the current name from a directory and puts a new name in a directory.


If you use the same directory, then it is a rename.


If you keep specify a different directory, but use the same name, then it is a move.


If you specify a different directory and a new name, it is both a move and a rename.


The current working directory is aways implied when you do not spaceify a directory.


The current name is always implied, when you only specify a destination directory.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

cp command won't work on terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.