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
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
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.
i thought that a .key or .txt or something similar wouldn't we counted as a directory so i would copy it normally, so is .key a directory?
Certainly a .txt is just a file, but the .key you have sounds like it is a "package" - a folder containing other files. In Finder, if you right-click on "Tidy room".key it should have Show Pakage contents as an option and if you selct that, it will navigate into it and show the contents.
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). 🙂
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.
Try
cp -R ~/Documents/"Tidy room".key ~/Documents/"maths g&t"
I presume "maths g&t" is a folder?
yes it is, thanks this worked, can i ask what does the flag -R do?
It's always a good idea to investigate the manual page (help page) for any command you want to run in the Terminal; just type man <command> e.g. man cp
thanks, really helped me
sorry to bother you but i don't really understand mv, the manual says it renames it and moves it to a destination directory, how can you just move it or just rename it and how can it do both?
Thank you very much - it's hard finding someone who can explain things from terminal well as well as not providing some dodgy code e.g. a fork bomb
😁
Yes Bob, thanks for the correction to my "Rename only" section, a mv within the same directory only changes the directory entry. In all other cases it is a copy and delete behind 🙂
Copy only happens if moving to a different Volume, otherwise it is remove name add name.
Thanks Bob, now I'm straight with it 🙂
cp command won't work on terminal