LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 04-01-2005, 01:08 AM   #1
netdemon
LQ Newbie
 
Registered: May 2002
Location: Northeast US
Distribution: Fedora
Posts: 24

Rep: Reputation: 15
cp command can't do "dotfiles"


This was a real frustration... To copy "dotfiles" like .bashrc with the "cp -R" command, you'd have to do "cp -R ./.* *", yet it'd try to copy ".." and "." in each directory, which doesn't work right. You could do a -R cp of regular files, then do an ls -a and some basename wizardry to copy "dotfiles" afterwards, but it wouldn't do dot directories (directories that start with dot).

After a while, I figured out I can do:

tar --exclude='.' --exclude='..' -cvf server-bak-2005-03-31.tar /mnt/tmphd/* /mnt/tmphd/.*

Finally, someone told me to do...

cp -R /mnt/tmphd/* /mnt/tmphd/.??* .

Still, I don't get why cp doesn't have a parameter to say "include dotfiles" and a parameter to say "include dotdirectories".

Should cp be modified to include this? If there is some secret hidden way, shouldn't it be better documented?

Last edited by netdemon; 04-01-2005 at 01:11 AM.
 
Old 04-01-2005, 01:35 AM   #2
overlord73
Member
 
Registered: Apr 2004
Location: ..where no life dwells..
Posts: 541

Rep: Reputation: 30
hi,
what is your intention...backup?

tar -cvzhf <dest.> <src.> should do
 
Old 04-01-2005, 03:28 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
That tar command doesn't look right. The last parameter listed as <dest.> would actually be the list of files to include in the archive.

You can use tar to copy files from one directory to another like this

cd <source dir>; tar cf - . | ( cd <dest dir> ; tar xf - )

I got this from the tar info pages. I'm working off of memory, so please double check it. I don't know if tar called like this will indeed pickup the hidden files/directories in the current directory.

Also double check if 'cp . <destination_dir> does not pick up hidden files. I think that the rational is that since these are hidden files, a user probably is only trying to copy files that they can see in a directory listing. Otherwise a person might be copying files that they are not aware of, which might include harmful files left by a hacker ( make that cracker ). Or perhaps a very large core file.
 
Old 04-01-2005, 03:49 AM   #4
overlord73
Member
 
Registered: Apr 2004
Location: ..where no life dwells..
Posts: 541

Rep: Reputation: 30
Quote:
Originally posted by jschiwal
That tar command doesn't look right. The last parameter listed as <dest.> would actually be the list of files to include in the archive.
works on my box.
tar -cvzhf backup.tar.gz /yourfolder.with.hiddenfiles

Quote:
Also double check if 'cp . <destination_dir> does not pick up hidden files.
hmm? not in my case....
 
Old 04-01-2005, 03:50 AM   #5
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
You could always do something like this:

cp \.??*

Which copies any file which begins with a . and has at least 2 other characters ( this eliminates the .. problem.)

Or:

for i in `find . -type f`;do cp $i /new/path/ ;done

<edit> Always quote your variables in case of spaces in filenames.

for i in `find . -type f`;do cp "$i" /new/path/ ;done

Last edited by /bin/bash; 04-01-2005 at 03:54 AM.
 
  


Reply



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
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
cdrecord command-line parentheses "(" ")" coolingtower Linux - Software 1 10-28-2005 11:49 AM
Tiny Sofa 2.0 - I thought "halt", "reboot" were only root command ?? sorcerer Linux - Distributions 1 08-21-2004 03:28 PM
About a "dotfiles" section slackie1000 LQ Suggestions & Feedback 5 04-19-2004 12:40 PM
"segmentation error" when issuing "useradd" command through terminal with RH 9.0 kaihuang Linux - General 0 10-21-2003 11:47 PM

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

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