#1 Le 21/11/2020, à 19:05
- oxibb
Extraction et déplacement de fichiers
Bonsoir à tous,
j'ai une question qui peut paraître idiote, mais je galère avec un truc :
j'ai dans un dossier 40000 photos dans des centaines de sous dossier, je cherche une commande/méthode pour extraire la totalité des fichiers et les copier ou déplacer dans le premier niveau d'un dossier ....
Avez-vous une idée ?
très belle soirée à vous tous
OXIBB
Hors ligne
#2 Le 21/11/2020, à 19:32
- Hizoka
Re : Extraction et déplacement de fichiers
Salut,
un truc du genre :
find . -type f -exec mv -i {} . \;
le type f prend tous les fichiers.
sinon il faut un trucx du genre -iname "*.jpg" si tu ne veux que les fichiers jpg
Mais fais une copie de ton dossier d'image avant.
KDE Neon 64bits
Tous mes softs (MKVExtractorQt, HizoSelect, HizoProgress, Qtesseract, Keneric, Services menus...) sont sur github
Hors ligne
#3 Le 21/11/2020, à 20:10
- oxibb
Re : Extraction et déplacement de fichiers
merci , je vais tester....
bonne soirée
Hors ligne
#4 Le 21/11/2020, à 20:35
- oxibb
Re : Extraction et déplacement de fichiers
voilà , merci beaucoup
voici la commande que j'ai utilisé :
find /home/toto/dossier_source -iname '*.jpg' -exec mv {} /home/toto/dossier_destination/ \;
oxibb
Hors ligne
#5 Le 21/11/2020, à 22:34
- kamaris
Re : Extraction et déplacement de fichiers
Petite optimisation :
find /home/toto/dossier_source -iname '*.jpg' -exec mv -t /home/toto/dossier_destination/ {} +
Sur 40 000 fichiers, ça pourrait commencer à se voir…
Hors ligne
#6 Le 21/11/2020, à 22:43
- Hizoka
Re : Extraction et déplacement de fichiers
je connaissais pas cette option pour mv, pas mal
KDE Neon 64bits
Tous mes softs (MKVExtractorQt, HizoSelect, HizoProgress, Qtesseract, Keneric, Services menus...) sont sur github
Hors ligne
#7 Le 22/11/2020, à 08:24
- oxibb
Re : Extraction et déplacement de fichiers
Petite optimisation :
find /home/toto/dossier_source -iname '*.jpg' -exec mv -t /home/toto/dossier_destination/ {} +
Sur 40 000 fichiers, ça pourrait commencer à se voir…
merci beaucoup, cela fonctionne bien , j'ai par contre découvert un problème , j'ai beaucoup de fichiers avec le même nom.
Serait-il possible de renomer chaque fichier dans la destination : img1 img2 img3 img4 et en gardan l'extension ?
merci pour votre aide.
Hors ligne
#8 Le 22/11/2020, à 10:17
- MicP
Re : Extraction et déplacement de fichiers
Bonjour
… Serait-il possible de renomer chaque fichier dans la destination : img1 img2 img3 img4 et en gardan l'extension ? …
Si la commande rename n'est pas installée,
il te faudra d'abord l'installer :
sudo apt install rename
Ensuite, la ligne de commande suivante fonctionnera comme tu le demandes :
find /chemin/rep_source/ -iname '*.jpg' -exec mv --backup=numbered -t /chemin/rep_destination/ {} + && rename 's/((?:\..+)?)\.~(\d+)~$/$2$1/' /chemin/rep_destination/*.~*~
Dernière modification par MicP (Le 22/11/2020, à 10:24)
Hors ligne
#9 Le 22/11/2020, à 13:32
- Compte supprimé
Re : Extraction et déplacement de fichiers
Bonjour,
@MicP:
Que signifit le ~ dans l'expression régulière de rename?
#10 Le 22/11/2020, à 13:50
- MicP
Re : Extraction et déplacement de fichiers
Bonjour pseudofab
… Que signifit le ~ dans l'expression régulière de rename?
Ce n'est pas un opérateur de l'expression rationnelle,
c'est simplement que l'option --backup=numbered de la commande mv
ajoute à la fin du nom des fichiers doublons
un point suivit d'un numéro entre deux caractères ~
Comme ci-dessous :
michel@ubuT450:~/tests$ ls -l
.:
total 0
michel@ubuT450:~/tests$
michel@ubuT450:~/tests$ mkdir src/{,src1,src2} repCible && touch src/{,src1/,src2/}"fich "{a..c}.jpg
michel@ubuT450:~/tests$ ls -lR src/ repCible/
repCible/:
total 0
src/:
total 8
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich a.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich b.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich c.jpg'
drwxrwxr-x 2 michel michel 4096 nov. 22 14:31 src1
drwxrwxr-x 2 michel michel 4096 nov. 22 14:31 src2
src/src1:
total 0
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich a.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich b.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich c.jpg'
src/src2:
total 0
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich a.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich b.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich c.jpg'
michel@ubuT450:~/tests$ find src/ -iname '*.jpg' -exec mv --backup=numbered -t repCible/ {} +
michel@ubuT450:~/tests$ ls -lR src/ repCible/
repCible/:
total 0
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich a.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich a.jpg.~1~'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich a.jpg.~2~'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich b.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich b.jpg.~1~'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich b.jpg.~2~'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich c.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich c.jpg.~1~'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich c.jpg.~2~'
src/:
total 8
drwxrwxr-x 2 michel michel 4096 nov. 22 14:32 src1
drwxrwxr-x 2 michel michel 4096 nov. 22 14:32 src2
src/src1:
total 0
src/src2:
total 0
michel@ubuT450:~/tests$ rename 's/((?:\..+)?)\.~(\d+)~$/$2$1/' repCible/*.~*~
michel@ubuT450:~/tests$ ls -l repCible/
total 0
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich a1.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich a2.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich a.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich b1.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich b2.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich b.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich c1.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich c2.jpg'
-rw-rw-r-- 1 michel michel 0 nov. 22 14:31 'fich c.jpg'
michel@ubuT450:~/tests$
michel@ubuT450:~/tests$ rm -rf src/ repCible/
michel@ubuT450:~/tests$
Dernière modification par MicP (Le 22/11/2020, à 21:30)
Hors ligne
#11 Le 22/11/2020, à 15:16
- Compte supprimé
Re : Extraction et déplacement de fichiers
Merci pour ta réponse, maintenant tout prend sens.
De plus, j'ai appris d'autres choses dans ton code explicatif
#12 Le 22/11/2020, à 21:31
- MicP
Re : Extraction et déplacement de fichiers
Cool ,
merci pour le retour
Hors ligne