LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-20-2015, 10:51 AM   #1
ballsystemlord
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 219

Rep: Reputation: Disabled
cp how to copy hidden files and copy recusively without over writing


Yes, I know, how hard can cp be?
I wanted to copy some of my hidden files from my home dir (backup reasons) so I issued the command:
Code:
cp ~/.* /dest/dir/
but it did not copy the files I wanted.
Again, I wanted to copy recusively with out overwriting the files so I issued the command:
Code:
cp -nr dir dest
The only problem is that though it does do the copy recusively with out over writing it misses many files because if dest containes
Code:
ls -R dir
drwx------  foo
-rw-------  bar

/foo:
baz
then cp will not write baz2 into foo (assuming baz2 is in dir). Dolphin has an option called write into all, but cp does not, as far as I can tell.
I could, of course, create an awk script that uses find and mkdir -p etc and copies all of them, but that is rather slow (I have done it).
I'm using bash version 4.2.53 on gentoo linux. coreutils version 8.21.

Thanks
 
Old 05-20-2015, 01:27 PM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 17,550

Rep: Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610Reputation: 2610
Have you tried 'cp -an'?

-a is a cumulative option for a lot of handy things.
 
Old 05-20-2015, 01:32 PM   #3
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Might be overkill but what about rsync?
 
Old 05-25-2015, 11:36 AM   #4
ballsystemlord
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 219

Original Poster
Rep: Reputation: Disabled
rsync is a little over kill.
As for -a it does not include what I was describing.
Perhaps I should ask the author of moreutils if such an app could be invented.
 
Old 05-25-2015, 01:50 PM   #5
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: One main distro, & some smaller ones casually.
Posts: 5,872

Rep: Reputation: Disabled
I usually just use cp -a, (which is equal to cp -dpR I believe).

As an example :-
Code:
 cp -a /home/* <somewhere>
copies everything under /home to <somewhere>

Edit: Can't remember if it copies . files, but if not, also use
Code:
cp -a /home/*/.* <somewhereelse>
should get everything copied.

Last edited by fatmac; 05-25-2015 at 01:55 PM.
 
Old 05-25-2015, 02:08 PM   #6
ballsystemlord
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 219

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fatmac View Post
I usually just use cp -a, (which is equal to cp -dpR I believe).

As an example :-
Code:
 cp -a /home/* <somewhere>
copies everything under /home to <somewhere>

Edit: Can't remember if it copies . files, but if not, also use
Code:
cp -a /home/*/.* <somewhereelse>
should get everything copied.
I just wanted to copy the hidden files so 1 will not help.
2 does work! Hmm, maybe my problem was something else when doing cp.

This first problwm may be considered solved until I find
something else in the way of evidence.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you copy hidden files from one directory to another? Akhran Linux - Newbie 22 12-13-2019 05:20 PM
[SOLVED] Writing a script that copy files to sub folder yoczor Programming 1 12-08-2013 03:32 AM
Writing to NFS share leaves local copy of files Mark_667 Programming 2 06-21-2012 05:40 AM
copy svn working dir without svn hidden dirs and files? erinspice Linux - Software 4 03-29-2011 05:58 PM
How can I copy hidden home directory configuration files and folders? rm_-rf_windows Linux - General 3 06-29-2007 05:26 AM

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

All times are GMT -5. The time now is 10:16 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