I have two existing directories :
- foo: directory with dotfiles in it
- foo2: empty directory
I would like to have a solution to copy all dotfiles in foo
to foo2. I would like a solution that is not shell-dependent (bash, zsh, etc.). I would prefer not having to install rsync
to do it (tar
is ok).
Weeks ago, I asked this similar question, but I feel both questions should be separated as they answer different needs. All answers were shell-dependent or using rsync
.
cp -r foo/.??* foo2/
? – Joseph R. Sep 15 '13 at 21:46-r
option will only copy files as directories will give thecp: omitting directory
error. – Drav Sloan Sep 15 '13 at 21:48??
? – Gradient Sep 15 '13 at 22:07.
and..
which would be... unpleasant. – Joseph R. Sep 15 '13 at 22:13for i in foo/.* ; do [ "$i" = "foo/." ] && continue ; [ "$i" = "foo/.." ] && continue ; cp -r "$i" foo2 ; done
(ie, list all .* and avoid "." and ".." only). It does copy file and/or directories as well. If you want only files, replace it by:for i in foo/.* ; do [ ! -f "$i" ] && { echo "skipping: $i" ; continue ; } ; cp -r "$i" foo2 ; done
– Olivier Dulac Oct 02 '13 at 18:10