Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

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

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 04:01 AM.
Old 02-24-2006, 03:23 PM   #2
LQ Guru
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 272Reputation: 272Reputation: 272
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, 03:35 PM   #3
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,138

Rep: Reputation: 168Reputation: 168
Can you use something like:
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, 03:44 PM   #4
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740
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, 03:51 PM   #5
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 just leave out the point and the star
cp -a /home/user1/ /target will result in /target/user1...and_everything
Old 02-25-2006, 04:42 AM   #6
Senior Member
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,606

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.


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 07:02 PM
home directory files gone, hidden files remain Grasshopper Linux - Security 12 04-10-2005 08:23 PM
Konqueror: Show hidden directories in directory tree Birdy Linux - Software 5 03-06-2005 10:58 PM
Hundreds of hidden files in home directory doobers Linux - Newbie 3 02-14-2005 02:57 PM
Cleaning Home hidden files melinda_sayang Linux - General 4 02-23-2004 02:02 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:37 PM.

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