Script Bash[2] – décompresser plusieurs fichiers – uncompress a bunch of files
Une astuce qui peut être trouvée sur howtogeek.com.
—
A tips that can be found on howtogeek.com.
Dans mon premier billet sur les scripts bash, je vous faisais voir comment faire une «sauvegarde» de vos fichiers.
Plus généralement,
for <var> in <list> ; do command $<var>; done
vous permet de traiter tous les fichiers contenu dans la liste <list>
Voilà un script pour dézipper, détarrer, … tous les fichiers contenus dans le dossier d’appel du script.
#!/bin/bash
#decomp.sh
#extrait tous les fichiers du répertoire dans le répertoire
for i in *.tar; do tar xvf $i;done
for i in *.tgz; do tar zxvf $i;done
for i in *.tar.gz; do tar zxvf $i;done
for i in *.gz; do gunzip $i;done
for i in *.zip; do unzip $i;done
for i in *.rar; do unrar xv $i;done
À vous d’ajouter (ou d’enlever) les extensions dont vous vous servez (pas). Attention à bien avoir unrar d’installé ici…
—
In my first post on the scripts bash, I showed you how to “make a backup” of your files.
In a more general way,
for <var> in <list>;do command $<var> ;done
allows to execute a command on all the files in the <list>.
Here is a script to unzip, untar, … all the files in the repertory.
#!/bin/bash
#decomp.sh
#extract all files in the repertory
for i in *.tar; do tar xvf $i;done
for i in *.tgz; do tar zxvf $i;done
for i in *.tar.gz; do tar zxvf $i;done
for i in *.gz; do gunzip $i;done
for i in *.zip; do unzip $i;done
for i in *.rar; do unrar xv $i;done
You can add (remove) extensions you (don’t) want. Be sure to have unrar installed…
Salut,
je te propose une autre solution :
for i in *; do
case $i in
*.tar) tar xvf $i;;
*.tgz) tar zxvf $i;;
*.tar.gz) tar zxvf $i;;
*.gz) gunzip $i;;
*.zip) unzip $i;;
*.rar) unrar xv $i;;
esac
done
sputnick :
http://sputnick1.wordpress.com/
sputnickwordpress said this on 2007, November 8 - Thursday at 11:45
Effectivement, c’est quand même mieux =)
Généralement, je n’utilise pas trop les switch/case, je commence avec un if-then-else, imbriqué avec un 2nd, puis un 3e … u_u
Quelle balise utilises-tu pour avoir tes scripts en couleur ?
loquehumaine said this on 2007, November 8 - Thursday at 16:39
“Quelle balise utilises-tu pour avoir tes scripts en couleur ?”
Où ça donc ?
sputnickwordpress said this on 2007, November 8 - Thursday at 19:14
ici par exemple :
http://sputnick1.wordpress.com/2007/08/08/7/
loquehumaine said this on 2007, November 8 - Thursday at 19:19
clic droit dessus, tu verras, c’est une image ;)
sputnickwordpress said this on 2007, November 8 - Thursday at 20:40
c’est une capture de vim avec l’activation de :
:syntax on
sputnickwordpress said this on 2007, November 8 - Thursday at 23:05
D’ac, merci, je pensais que tu utilisais la balise sourcecode : http://faq.wordpress.com/2007/09/03/how-do-i-post-source-code/
chez moi ça ne marche pas trop :p
loquehumaine said this on 2007, November 9 - Friday at 15:06
merci pour le script
Toublanc said this on 2013, December 4 - Wednesday at 01:44