LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-13-2013, 07:27 AM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,432

Rep: Reputation: 110Reputation: 110
Copy recursively ignoring links


I need to copy an entire directory, recursively. And I need to ignore links. It's part of a script and I really need to do that.

'cp --no-dereference' doesn't work for me, because it copies the links. It doesn't follow them, but tries to copy them.

I've read 'man cp' a dozen times and if there is a way to ignore links, it's very well hidden.

Any suggestions?
 
Old 06-13-2013, 08:29 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
Have you considered using 'find' to select the files for you.
Use the '-type f' and -P' switches
Quote:
-P

Never follow symbolic links. This is the default behaviour. When find examines or prints information a file, and the file is a symbolic link, the information used shall be taken from the properties of the symbolic link itself.
http://linux.die.net/man/1/find
 
Old 06-13-2013, 08:47 AM   #3
archShade
Member
 
Registered: Mar 2006
Location: Delft NL
Distribution: Debian; Slackware; windows 7
Posts: 218

Rep: Reputation: 53
If you can stand to copy the links, then remove them you could use the find command.

Code:
cp -r --no-derefrence <src> <dest>
Then remove the links with the find command.
Code:
find <dest> -type l -delete
~~EDIT~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I have just seen the previous solution, and it's better. Having come up with my
solution I thought I ought to do at least a minimal test to make sure my solution
worked.

Last time I posted without testing I added an unneeded (that actually did not
exist) flag .

Last edited by archShade; 06-13-2013 at 08:54 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
copy recursively across directories stefaandk *BSD 1 11-09-2008 10:01 PM
how to copy images recursively via bash mindfriction Programming 6 12-13-2007 10:25 PM
Using cp to copy directory permissions recursively? SirTristan Linux - Newbie 3 11-25-2007 08:36 AM
trying to recursively copy jpegs DJOtaku Linux - General 10 08-26-2005 01:09 PM
ripping all links of a site recursively rsingh Linux - Newbie 1 10-29-2003 02:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:40 AM.

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