LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 10-20-2012, 01:37 PM   #1
average_user
Member
 
Registered: Dec 2010
Location: Warsaw, Poland
Distribution: Slackware
Posts: 560

Rep: Reputation: 220Reputation: 220Reputation: 220
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?
 
Old 10-20-2012, 03:18 PM   #2
FrankP
Member
 
Registered: Aug 2003
Location: Britain
Distribution: AntiX, Debian, Gentoo
Posts: 65

Rep: Reputation: 18
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?
 
Old 10-20-2012, 03:47 PM   #3
average_user
Member
 
Registered: Dec 2010
Location: Warsaw, Poland
Distribution: Slackware
Posts: 560

Original Poster
Rep: Reputation: 220Reputation: 220Reputation: 220
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?
 
Old 10-20-2012, 04:15 PM   #4
FrankP
Member
 
Registered: Aug 2003
Location: Britain
Distribution: AntiX, Debian, Gentoo
Posts: 65

Rep: Reputation: 18
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
 
Old 05-24-2018, 06:14 AM   #5
Rascal7
LQ Newbie
 
Registered: May 2018
Posts: 1

Rep: Reputation: Disabled
mv: cannot overwrite non-directory

Hi, I am trying to transfer some test files older than a specific date to another directory. I get the same error when I try to run my script.
find /INTER/f/d/o/ -name 'test*.txt' -mtime +190 -type f -exec mv /ARCHIVE/f/d/o/ {} \;


mv: cannot overwrite non-directory ./test1.txt with directory /ARCHIVE/f/d/o
mv: cannot overwrite non-directory ./test2.txt with directory /ARCHIVE/f/d/o
mv: cannot overwrite non-directory ./test3.txt with directory /ARCHIVE/f/d/o
mv: cannot overwrite non-directory ./test4.txt with directory /ARCHIVE/f/d/o

Can someone please give me any suggestions on what to do. I have been changing this script multiple times with no success and searching the web. Thanks
 
Old 05-26-2018, 01:27 AM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
please open a dedicated thread and take the time and effort to formulate a full problem description.
the first link in my signature might help.
please use code tags for adding code to your post.
 
  


Reply

Tags
cp



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash - rename directory to overwrite existing LarsWestergren Linux - Newbie 18 04-04-2013 02:07 PM
Username & Password Sync Fedora Directory and Microsoft Active Directory karnac01 Fedora 4 07-19-2010 12:51 AM
change default vsftp anonymous accout directory /var/ftp to other directory? hocheetiong Linux - Newbie 2 01-24-2010 06:33 PM
mv: cannot overwrite directory `/home/tcma/src/buildroot/build_i386/linux-2.4.27-tcma tcma Linux - Software 1 10-05-2004 03:46 PM
overwrite directory copy medamnit Linux - Newbie 1 05-26-2002 12:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration