Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Watch for undocumented behavior of cp -R' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Watch for undocumented behavior of cp -R
Authored by: TvE on Nov 16, '05 07:31:25AM

"The man page for cp says that cp -R directory1 directory2 "…
then WHY do you do somehing different like:
"cp -R directory1/ directory2/" ???

I mean - you're clearly adding characters to the command but still expect it to do what you THINK about.

I am fairly sure the difference is there for a reason, and I actually find it very logical:
"/blablabla/" means the content of the directory "/blablabla" and "/blablabla" is the before mentioned folder AND all it's content…



[ Reply to This | # ]
Watch for undocumented behavior of cp -R
Authored by: allanj37 on Nov 16, '05 07:47:36AM

Yes, this behavior is logical if you think about it, but the point is that it is still easy to accidently do the wrong one, especially with tab-completion.



[ Reply to This | # ]
Watch for undocumented behavior of cp -R
Authored by: adrianm on Nov 16, '05 08:06:01AM

If you use zsh instead of bash, the trailing slash is removed after tab completion if you don't do anything else with it.

Reason to use zsh #472



[ Reply to This | # ]
more dangerous
Authored by: melvinwalker on Nov 16, '05 10:56:49AM

Which is exactly why command lines are considered more dangerous than a GUI.

If someone wants to experiment with the command line, do it in a user account that has a lot of restrictions first. That's not always possible, but it's safer than using your administrator account.



[ Reply to This | # ]
Watch for undocumented behavior of cp -R
Authored by: auricgoldfinger on Nov 16, '05 12:02:52PM

Well, / is a delimiter to identify folder-files. So it actually isn't quite logical that you copy the directory under folder/ without copying the folder itself too.

And why you would do the cp -R folder/ thing?
mkdir temporary
cp -R tem<tab>

If you hit the tab then, bash will autocomplete to "temporary/"
Note the trailing slash?
That's why someone would like to add the /



[ Reply to This | # ]