LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-24-2006, 03:52 PM   #1
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,605

Rep: Reputation: 53
solved recursive backup of hidden files cp -a /home/user1/,* goes up the tree


Hello,
backing up /home/user1/.* with cp -a is not only backing up the hidden files
but also up the tree because .* is like ..
(and as the script runs as root, all the files and directories from /home end up copied.

How can I avoid this?

cp -av --target-directory=/home2/test /home/user1/*
is working ok, but does not save the hidden files and directories.

At the minute I am making one simple bash script to backup
one user data from one HD to another.

I know how to use dd, I know rsync, and amanda are out there.
What nags me is the "all hidden files in linux".
Maybe I should use /home/user1/.*.* or something of the like.
Anyhow I am struggling now, I have looked around but no solution in view.
Help will be appreciated.

Last edited by Emmanuel_uk; 02-25-2006 at 05:01 AM.
 
Old 02-24-2006, 04:23 PM   #2
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 271Reputation: 271Reputation: 271
Can't you just leave the * off? I feel like cp /home2/test /home/user1 should work, but I'm no expert...
 
Old 02-24-2006, 04:35 PM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
Can you use something like:
Code:
cp -av /home/user1 /home2/test
That just copies the user1 directory to /home2/test and creates the directory /home2/test. However, if /home2/test already exists, it will end up with a user1 directory below it. It just depends on whether this is a one-off copy or you'll be updating files.
 
Old 02-24-2006, 04:44 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Recursive copy means copy the directory and everything below it.

So just do cp -R <dirname> <destination>

What am I missing?
 
Old 02-24-2006, 04:51 PM   #5
jomen
Senior Member
 
Registered: May 2004
Location: Leipzig/Germany
Distribution: Arch
Posts: 1,687

Rep: Reputation: 54
cp -a will copy all files - the hidden ones too...so just leave out the point and the star
cp -a /home/user1/ /target will result in /target/user1...and_everything
 
Old 02-25-2006, 05:42 AM   #6
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,605

Original Poster
Rep: Reputation: 53
Thank you all. Indeed just need to drop the dot and the star. and it works. Problem solved.

Now then, I realised, this created another question:
how can one copy *only* the hidden files, still with cp -a (this is more academic than practical)
Is there a way without using find, grep, and ls?

there is no option for hidden files with find. I could only think of piping
something like ls -A -R | grep '^\.' to cp

Old dos ways and trying too hard could not me think straight.
It is odd once in while I have these rather daft questions.
 
  


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 to use /dev/hdb1 for /home/user1 malaka56 Linux - Software 1 10-22-2005 08:02 PM
home directory files gone, hidden files remain Grasshopper Linux - Security 12 04-10-2005 09:23 PM
Konqueror: Show hidden directories in directory tree Birdy Linux - Software 5 03-06-2005 11:58 PM
Hundreds of hidden files in home directory doobers Linux - Newbie 3 02-14-2005 03:57 PM
Cleaning Home hidden files melinda_sayang Linux - General 4 02-23-2004 03:02 AM


All times are GMT -5. The time now is 03:26 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration