Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
10-20-2012, 01:37 PM
|
#1
|
|
Member
Registered: Dec 2010
Posts: 30
Rep:
|
cp: cannot overwrite directory with non-directory
Slackware 13.37 x64, cp (GNU coreutils) 8.11
The error as in subject occurred to me when I tried to upgrade Mediawiki on the remote Ubuntu server. I don't have access to this server at the moment but the flow that led me the error was as follows:
Code:
mkdir ~/symlinks
cd ~/symlinks
mkdir ~/symlinks-target/
mkdir dir
mkdir dir/symlink
ln -s ~/symlinks-target/ symlink
cp -r symlink dir/
In this situation what's the easiest way to replace directories in 'dir' with symlinks? In there a command for that or it's necessary to write a script that will traverse the entire source directory, and if there will be a directory with the same name in the output directory it will rm it and copy a symlink after that?
|
|
|
|
10-20-2012, 03:18 PM
|
#2
|
|
Member
Registered: Aug 2003
Location: Britain
Distribution: Debian, MacOSX, FreeBSD
Posts: 65
Rep:
|
The error occurs, in your example, because when you copy the symlink called 'symlink' into the directory called 'dir', there is already an object named 'symlink' residing there, although it is a directory! Understanding the situation was made harder by the rather confusing names!
If you try this:
cd ~/symlinks
rmdir dir/symlink
cp -r symlink dir/
.. then you should find in 'dir' a new copy of the symlink called 'symlink' pointing to the directory ~/symlinks-target (which should work as long as the link was created with an absolute path not a relative one).
Will this accomplish what you want?
|
|
|
|
10-20-2012, 03:47 PM
|
#3
|
|
Member
Registered: Dec 2010
Posts: 30
Original Poster
Rep:
|
Yes, it will, and I know it:
Quote:
|
if there will be a directory with the same name in the output directory it will rm it and copy a symlink after that?
|
But what if there are multiple directories I need to copy, is there some cp switch that could be used or maybe someone has already written a script that could take care of this and possible pitfalls?
|
|
|
|
10-20-2012, 04:15 PM
|
#4
|
|
Member
Registered: Aug 2003
Location: Britain
Distribution: Debian, MacOSX, FreeBSD
Posts: 65
Rep:
|
Ah, sorry, my mistake -- I missed the part of your OP that you just quoted.
So you need to detect when there is already a directory there, if so remove it, and replace with a symlink of the same name to somewhere else? Someone may come up with some really nifty way of doing that with a combo of find and xargs or something, but for safety yes I would have thought a script would be needed. Because, as you say, of the "pitfalls".
You might be able to work around it by making sure all the objects you are replacing are always symlinks, and never actual directories. This could work for keeping a set of files up-to-date when only some are superseded on each update, if that's your situation for example.
Last edited by FrankP; 10-20-2012 at 04:17 PM.
Reason: Corrections for clarity
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:27 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|