Rechercher : dans
Par :

Copie récursive de fichiers cachés

Dernière réponse le 5 mai 2008 à 11:36:26 Atma, le 4 nov 2005 à 23:42:32 
 Signaler ce message aux modérateurs

Bonjour à tous !
Ma question est relativement simple : comment copier les fichiers cachés lorsqu'on fait une copie récursive ?

En effet, lorsque je fais

cp -pR monRep/* repDest/


Les fichiers cachés ne sont pas copiés (nota: je ne VEUX PAS copier le répertoire monRep dans repDest ... mais seulement les fichiers/dossiers constitutifs de ce répertoire => pas de "cp -pR monRep/ repDest/" !)

Maintenant, lorsque je fais :
cp -pR monRep/.* repDest/


Il "s'amuse à "remonter" dans les répertoires au-dessus de monRep/ : normal car ".." satisfait la regex ".*" grr

Donc ce à quoi j'ai pensé, ca aurait été d'utiliser une regexp .. le probleme est que visiblement ce ne sont pas des regexp que je "connais" puisque lorsque je fais un truc du genre :
cp -pR monRep/.[^.]* repDest/


Ca ne marche pas :'(

Si quelqu'un pouvait m'aider ca serait sympa :)
D'avance merci

1

mamiemando, le 5 nov 2005 à 00:37:26

(~) $ mkdir test
(~) $ cd test
(~/test) $ touch .plop1
(~/test) $ touch .plop2
(~/test) $ touch plop3
(~/test) $ cd ..
(~) $ cp -r test/ test2
 (~) $ ls -al test2
total 8
drwxr-xr-x   2 mando users 4096 nov  5 00:35 .
drwx------  58 mando users 4096 nov  5 00:35 ..
-rw-r--r--   1 mando users    0 nov  5 00:35 .plop1
-rw-r--r--   1 mando users    0 nov  5 00:35 .plop2
-rw-r--r--   1 mando users    0 nov  5 00:35 plop3

Bonne chance

Répondre à mamiemando

2

Atma, le 5 nov 2005 à 00:53:29

Ca ne m'intéresse de faire comme ça :)
je l'ai deja dit d'ailleurs ... "pas de "cp -pR monRep/ repDest/" " ;)
je veux copier les fichier/dossiers du répertoire et non le répertoire lui-même !

Répondre à Atma

3

jisisv, le 5 nov 2005 à 06:51:12

Un petit coup de 'compound commands' et de tar sous bash:

johand@horus:~/tmp/testcache$ mkdir rep1 rep2
johand@horus:~/tmp/testcache$ ls -al rep1 rep2
rep1:
total 8
drwxr-xr-x  2 johand johand 4096 2005-11-05 06:45 .
drwxr-xr-x  4 johand johand 4096 2005-11-05 06:45 ..

rep2:
total 8
drwxr-xr-x  2 johand johand 4096 2005-11-05 06:45 .
drwxr-xr-x  4 johand johand 4096 2005-11-05 06:45 ..
johand@horus:~/tmp/testcache$ touch rep1/brol rep1/.h1 rep1/.h2
johand@horus:~/tmp/testcache$ (cd rep1 ; tar -c .)| (cd rep2 ;tar -x )
johand@horus:~/tmp/testcache$ ls -al  rep2
total 8
drwxr-xr-x  2 johand johand 4096 2005-11-05 06:45 .
drwxr-xr-x  4 johand johand 4096 2005-11-05 06:45 ..
-rw-r--r--  1 johand johand    0 2005-11-05 06:45 brol
-rw-r--r--  1 johand johand    0 2005-11-05 06:45 .h1
-rw-r--r--  1 johand johand    0 2005-11-05 06:45 .h2
Gates gave you the windows.
GNU gave us the whole house.(Alexandrin)

Répondre à jisisv

4

Atma, le 5 nov 2005 à 15:51:37

Huhu ca a l'air compliqué :)
Entretemps, j'ai trouvé la solution : cp n'utilise pas de RegExp mais des "expressions du shell" ... du coup "tout caractere sauf le point" s'écrit [!.] et non [^.] :)

cp -r monRep/.[!.]* repDest/

fais exactement ce que je veux :)

Merci a tout le monde :)

Répondre à Atma

5

ME.here, le 5 mai 2008 à 11:08:14

Merci pour ta solution Atma !

Répondre à ME.here

6

 lami20j, le 5 mai 2008 à 11:36:26

Salut,

pour l'info

si en 2005 [^.] ne fonctionnais pas, alors en 2008 il fonctionne ;-)

root@debian:~/cache# ls -l
total 0
-rw-r--r-- 1 root lami20j 0 2008-05-05 11:35 b
-rw-r--r-- 1 root lami20j 0 2008-05-05 11:36 c
root@debian:~/cache# ls -al
total 1484
drwxr-xr-x  2 root lami20j    4096 2008-05-05 11:36 .
drwxr-xr-x 25 root lami20j 1511424 2008-05-05 11:34 ..
-rw-r--r--  1 root lami20j       0 2008-05-05 11:34 .a
-rw-r--r--  1 root lami20j       0 2008-05-05 11:35 b
-rw-r--r--  1 root lami20j       0 2008-05-05 11:34 .b
-rw-r--r--  1 root lami20j       0 2008-05-05 11:36 c
root@debian:~/cache# ls -al .[!.]*
-rw-r--r-- 1 root lami20j 0 2008-05-05 11:34 .a
-rw-r--r-- 1 root lami20j 0 2008-05-05 11:34 .b
root@debian:~/cache# ls -al .[^.]*
-rw-r--r-- 1 root lami20j 0 2008-05-05 11:34 .a
-rw-r--r-- 1 root lami20j 0 2008-05-05 11:34 .b

106485010510997108

Répondre à lami20j