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? |
hi,
what is your intention...backup? tar -cvzhf <dest.> <src.> should do |
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. |
Quote:
tar -cvzhf backup.tar.gz /yourfolder.with.hiddenfiles Quote:
|
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 |
All times are GMT -5. The time now is 05:53 PM. |