à mettre dans son bashrc
showOriginal() {
packageName=$(dpkg -S $1|cut -d':' -f1)
tmpdir="/tmp/showOriginal-$packageName-$(date +%s)"
mkdir $tmpdir
cd $tmpir
apt-get download $packageName > /dev/null
dpkg -x *.deb $tmpdir
cat ${tmpdir}$1
cd - >/dev/null
rm -rf $tmpdir
}
-
https://links.infomee.fr/?tdQ_tAjusqu'à présent j'utilisais des alias dans mon bashrc du genre :
cdbackup() { cd /home/foo/backup/; }
Mais la méthode proposée est bien plus pratique
-
http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.htmlzsh ça a l'air bien quand même. Le coup des alias inline ça rox ( gp=|grep -i )
-
http://www.slideshare.net/jaguardesignstudio/why-zsh-is-cooler-than-your-shell-16194692Bien pratique pour intéragir avec le pressepapier en cmdline, exemple :
function nowplz {
xclip -i <<< $(date "+%Y-%m-%d %H:%M")
}
va copier dans le presse papier la date et l'heure actuelle
-
http://doc.ubuntu-fr.org/xclipbien utile
cat liste | parallel --gnu -j 10 ssh root@{} 'ls'
-
http://blog.michaelboman.org/2012/04/running-commands-in-parallel-using-bash.htmlPour obtenir la diff des éléments entre deux listes :
To get the lines only in the old file:
comm -23 <(sort /tmp/oldList) <(sort /tmp/newList)
To get the lines only in the new file:
comm -13 <(sort /tmp/oldList) <(sort /tmp/newList)
comm -23 <(sort /tmp/1) <(sort /tmp/2)
comm -13 <(sort /tmp/1) <(sort /tmp/2)
-
http://stackoverflow.com/questions/11165182/bash-difference-between-two-listsPratique pour l'écriture de script en bash lorsqu'on a besoin d'un fichier temporaire :
#Creation
tmpfile=$(mktemp)
#Utilisation...
#Clean
if [ -e "$tmpfile" ]
then
rm -f $tmpfile
fi
-
https://links.infomee.fr/?r6stZwYou can avoid this by temporarily removing the indentation for the lines of your Heredocs. However, that distorts your pretty and consistent indentation. There is an alternative. If you use <<-END instead of <<END as your Heredoc operator, Bash removes any tab characters in the beginning of each line of your Heredoc content before sending it to the command. That way you can still use tabs (but not spaces) to indent your Heredoc content with the rest of your code. Those tabs will not be sent to the command that receives your Heredoc. You can also use tabs to indent your sentinel string.
-
http://mywiki.wooledge.org/BashGuide/InputAndOutputCool stuff :
ssh user@server 'bash -s' < local_script.sh > local_script.log 2>&1
-
https://links.infomee.fr/?ORnmyQSympa tous ces one liners ! il y a même un repo dans lequel on peut ajouter les siens : https://github.com/fxn/tkn
Mes préférés :
$ echo "!!" > script.sh
$ cp file.txt{,.bak}
$ (cd /tmp && ls)
$ nc -l 5566 > data-dump.sql
$ nc <his-ip-address> 5566 < data-dump.sql
via Olivier
-
http://arturoherrero.com/2013/11/29/command-line-one-liners/function sayhello() {
echo hello
}
OR
sayhello() {
echo hello
}
Et en one-line :
sayhello() { echo hello; }
-
https://links.infomee.fr/?zlvmKwJe prefere la deuxieme solution :
function myfunc()
{
local myresult='some value'
echo "$myresult"
}
result=$(myfunc) # or result=myfunc
echo $result
-
http://www.linuxjournal.com/content/return-values-bash-functionsComment déclarer et itérer sur un tableau associatif en bash :
declare -A array
array[foo]=bar
array[bar]=foo
for i in "${!array[@]}"
do
echo "key : $i"
echo "value: ${array[$i]}"
done
-
http://stackoverflow.com/questions/3112687/how-to-iterate-over-associative-array-in-bashUn truc pour faire du screencast de terminal, ça peut servir
-
http://showterm.io/Old mais je viens d'y repenser. Finalement je fais pareil, j'ai des mémo pour chaque commande dans un dossier de mon dropbox alors pourquoi pas essayer de les utiliser avec ça ? à tester. Dans tous les cas ça ne doit pas remplacer le man
-
http://korben.info/cheat-pour-vous-souvenir-de-la-bonne-syntaxe.html