Copying folder (cp), need to mention destination parent folder only?

P

postcd

Guest
Hello,

when i copy some folder (myfolder) and its subfolders i do:

a) cp /home/src/myfolder /home/dst/myfolder
b) cp /home/src/myfolder /home/dst/

?

after "myfolder" do i need to create slash? thank you
 


Hi,
see man for mkdir and copy options (-R)
+ your favourite search engine should provide numerous results
 
It's the difference between a file (no /) and a directory/folder (/)

You are looking for the cp command. You need to change directories so that you are outside of the directory you are trying to move. If the directory you're moving is called dir1 and you want to move it to your /home/Pictures folder:

cp -r dir1/ ~/Pictures/

Linux is case-sensitive and also needs the / after each directory to know that it isn't a file. ~ is a special character in the terminal that automatically evaluates to the current user's home directory. If you need to know what directory you are in, use the command pwd

When you don't know how to use a Linux command, there is a manual page that you can refer to by typing

man [insert command here]

at a terminal prompt.

Also, to auto complete long file paths when typing in the terminal, you can hit Tab after you've started typing the path and you will either be presented with choices, or it will insert the remaining part of the path.
http://stackoverflow.com/questions/...er-with-files-to-another-folder-in-unix-linux
 
so i must not use /src/folder/ /dst/folder/ but /src/folder/ /dst/ ?
 
You need to read the man pages, that's what they're there for, or do you think someone just sits down and writes these for the hell of it?

The trailing slash indicates that it is definitely a directory. But is not needed for what you want to do.

For example
Code:
# cp -R /src/folder /dst
can have two outcomes:

- If dst does not exist, a file called dst will be created (containing a lot of junk)

- If dst exists, then the result will be: /dst/src/folder

The preceding slash assumes that you're working on the / (root) directory. If this is not the case, then do these operations in your own users /home/my_user directory, e.g.
Code:
$ cp -R ~/src/folder ~/dst
If you don't know what you're doing, copying files around the / directory could easily lead to disaster.
 
Last edited:

Staff online

Members online


Top