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
 
LinkBack Search this Thread
Old 08-23-2004, 04:45 AM   #1
Frustin
Member
 
Registered: May 2002
Location: Essex, UK
Distribution: Debian, Redhat, AIX 5L
Posts: 511

Rep: Reputation: 30
copying hidden files


how do you copy hidden files from one directory to another?
 
Old 08-23-2004, 04:52 AM   #2
b0uncer
Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
if you mean the "hidden files" as the files that have dot in front of their filenames (like .xinitrc or .bash_profile), then their copying goes quite normally from the command line: (the first example means you're in the directory you copy the files from, and the second is with full paths)

Code:
cp ./.hiddenfile /path/to/another/place/
and the 2nd example:

Code:
cp /path/to/file/.hiddenfile /another/path/
 
Old 08-23-2004, 04:57 AM   #3
Frustin
Member
 
Registered: May 2002
Location: Essex, UK
Distribution: Debian, Redhat, AIX 5L
Posts: 511

Original Poster
Rep: Reputation: 30
i know how to copy one hidden file. i mean to copy _all_ of them at the same time (there are loads).
 
Old 08-23-2004, 04:58 AM   #4
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix, 98,2000 + various
Posts: 3,171

Rep: Reputation: 51
cp .* otherplace
 
Old 08-23-2004, 05:01 AM   #5
Frustin
Member
 
Registered: May 2002
Location: Essex, UK
Distribution: Debian, Redhat, AIX 5L
Posts: 511

Original Poster
Rep: Reputation: 30
ah yes, if you are in the directory you want to copy from it works, but if you are in the directory you want to copy to, it doesnt, it start copying everything up from that as well.

Last edited by Frustin; 08-23-2004 at 05:03 AM.
 
Old 08-23-2004, 03:43 PM   #6
b0uncer
Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
try:

Code:
cp /the/dir/where/you/copy/from/.* ./
the first dir comes with full path, and at the place of the filename is simply .* (dot and asterisk) which means "all files that begin with a dot". the second path is simply ./ (dot and slash), which represents the current directory - the one you're in at the moment. you could also specify the full path as the second directory and the files would be copied to there...
 
Old 08-24-2004, 02:41 AM   #7
Frustin
Member
 
Registered: May 2002
Location: Essex, UK
Distribution: Debian, Redhat, AIX 5L
Posts: 511

Original Poster
Rep: Reputation: 30
thats the one that doesnt seem to work, or is it if you use the -a option with it perhaps? it seems to copy up from that directory as well.
 
Old 08-24-2004, 03:23 AM   #8
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
The problem is this:

when you use the full path with the .* wildcard, it matches two special entries:
"." - the current directory
".." - the parent directory

You can prevent that by changing your command to this:
cp /the/dir/where/you/copy/from/.[^\.]* ./

What that says is, "Copy everything that starts with a dot and does not have a dot as the second character". Since the current directory is a single dot, this won't match it, and since the parent directory is two dots, this won't match it either. However, if you have any files such as "..some_file", they won't be copied over either (very unlikely). If you do, though, then I would suggest using the find command or a simple shell script rather than cp.

Last edited by Dark_Helmet; 08-24-2004 at 03:26 AM.
 
Old 08-24-2004, 03:52 AM   #9
Frustin
Member
 
Registered: May 2002
Location: Essex, UK
Distribution: Debian, Redhat, AIX 5L
Posts: 511

Original Poster
Rep: Reputation: 30
thanks all.
 
Old 08-27-2004, 12:20 AM   #10
jonr
Senior Member
 
Registered: Jan 2003
Location: Kansas City, Missouri, USA
Distribution: Ubuntu
Posts: 1,040

Rep: Reputation: 47
Quote:
Originally posted by Dark_Helmet
The problem is this:

when you use the full path with the .* wildcard, it matches two special entries:
"." - the current directory
".." - the parent directory

You can prevent that by changing your command to this:
cp /the/dir/where/you/copy/from/.[^\.]* ./
I was aware of the problem, but had not been able to find the answer. Now I know the answer! Thanks very much, Dark_Helmet.

I use cp to copy rapidly all my home directory files as often as I want to to another hard drive. It has been working fine, except for all the screensful of error messages relating to the dot representing the current directory! Now I will have a neater, and a little bit faster, routine.

I also use two other backup methods, which take a lot longer, to copy less often system files and home files, but for some reason they are neither one as foolproof as the plain cp command. They don't always capture all the files, while cp does.

I'm reluctant to use tar with gzip because I've read that gzipped files are useless past the point of one single error in the archive.
 
Old 08-27-2004, 12:45 AM   #11
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
Actually, the command I gave works, but the backslash is not needed. In other words, this will work also:
Code:
cp /the/dir/where/you/copy/from/.[^.]* ./
That backslash snuck in by dealing with application that have different rules for regular expressions... not that important though.

Yes, it is possible for a gzip archive to become corrupt, but you can always test it. Tar has a verify option (-W, --verify) to check an archive file once it's created. If it fails, you can try again. If it checks out, then you're good to go. The media you store it on might get corrupted at some point, but you run that risk with anything: hard drive failure, floppy disk going bad, CDR getting scratched, etc.

You don't have to use it if you're not comfortable with it. Just realize that lots of software projects provide their programs in a gzip'ed tar format. So, archive corruption can't be that big a problem. On a personal note, I've never come across a corrupt gzip archive.
 
Old 08-27-2004, 01:24 AM   #12
jonr
Senior Member
 
Registered: Jan 2003
Location: Kansas City, Missouri, USA
Distribution: Ubuntu
Posts: 1,040

Rep: Reputation: 47
Quote:
Originally posted by Dark_Helmet

That backslash snuck in by dealing with application that have different rules for regular expressions... not that important though. [...] On a personal note, I've never come across a corrupt gzip archive.
Well, I must admit I felt proud to recognize what the backslash did--I'm trying to learn regular expressions and simple scripting, but it's an uphill climb. I'll just leave it in there.

Good to know about the verifying process with tar and gzip, and that gzip may not be a problem after all. Tar is certainly a handy and relatively simple way to make very quick copies. I'll probably head back in that direction now! Thanks again.
 
Old 08-27-2004, 02:12 AM   #13
Frustin
Member
 
Registered: May 2002
Location: Essex, UK
Distribution: Debian, Redhat, AIX 5L
Posts: 511

Original Poster
Rep: Reputation: 30
you mean an "uphill struggle", if your going uphill you are by default climbing. </pendent>
 
Old 08-27-2004, 06:07 AM   #14
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix, 98,2000 + various
Posts: 3,171

Rep: Reputation: 51
you could use bzip2 with tar. it's safer.

Data recovery
bzip2 compresses blocks of data independent from each other. For each block, a checksum is created and stored. That's why all non-corrupted compressed data blocks can be easily detected and recovered. The tool bzip2recover which is available from the bzip2 homepage can do this.
 
Old 08-27-2004, 06:32 AM   #15
Frustin
Member
 
Registered: May 2002
Location: Essex, UK
Distribution: Debian, Redhat, AIX 5L
Posts: 511

Original Poster
Rep: Reputation: 30
doesnt bzip2 compress better than gzip as well?
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying hidden files recursively? mrd Linux - General 1 09-30-2005 07:51 AM
home directory files gone, hidden files remain Grasshopper Linux - Security 12 04-10-2005 08:23 PM
hidden files Alwyn Linux - Newbie 2 01-27-2005 12:20 AM
Hidden Files Alien18 Linux - Newbie 4 08-12-2004 09:38 PM
Copying Hidden Directories Guru3 Linux - General 1 12-05-2003 12:59 PM


All times are GMT -5. The time now is 05:51 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration