Unbekannte, aber nützliche Unix-Tools

Axel Beckert

LUGS / Debian / ETH Zürich

abe@debian.org
http://noone.org/abe/

Übersicht

  • Mehrere Dateien auf einmal umbenennen
  • Varianten und Tipps zu "tail", "du" und "df"
  • Mehrere Prozesse auf einmal killen
  • Wie generiere ich zufällige Passwörter?
  • Farbe auf der Kommandozeile
  • Wie teste meinen Mailserver?
  • Ping auf Drogen
  • WebDAV auf der Kommandozeile
  • Paralleles Ausführen von Befehlen
  • Weitere Ressourcen / Links

Mehrere Dateien auf einmal umbenennen

Problem: Da unter Unix die Shell die Wildcards auswertet, geht mv *.jpg *.jpeg im Gegensatz zu DOS nicht.

Lösung: Diverse Tools: (p)rename aus "perl"; rename.ul aus "util-linux"; qmv, qcp, imv, icp und deurlname aus "renameutils".

$ mmv '*.jpg' '#1.jpeg'            $ mmv '*---*' '#1 - #2'
$ prename 's/jpg$/jpeg/' *.jpg     $ prename 's/_/ /g' *.ogg
$ rename.ul jpg jpeg *.jpg         $ rename.ul Wierd Weird *.ogg
$ qmv *.ogg                        $ qcp *.jpg
$ vidir .
$ deurlname bla%20foo → "bla foo"  $ convmv -f latin1 -t utf-8 *.ogg
$ detox äöü---èéëê_\ _ß → aou-eeee_ss

Varianten von "du", "df" und "tail"

$ df -h;  df -H  # Menschenlesbare Größenangaben
$ df -l          # Nur lokale Dateisysteme
$ df -T          # Auch Dateisystemtyp ausgeben
$ df -P          # POSIX-Format, ohne Umbrüche in den Einträgen
$ df -P | column -t  # column ist im Paket bsdmainutils
$ mount | column -t

$ du -h | sort -h  # Sortiert menschenlesbare Größenangaben
$ du | xdu         # Grafische Darstellung der Ausgabe
$ xdiskusage       # Grafisches "du"
$ ncdu             # Text-Modus "du"

$ tail -F datei     # Folgt auch neuer Datei, z.B. nach Logrotation
$ inotail -f datei  # Nutzt inotify, flüssige, sofortige Ausgabe
$ since datei > /dev/null; sleep 3; since datei
$ buthead 3 datei || tail -n +3 datei
$ multitail datei1 datei2 datei3

Mehrere Prozesse auf einmal killen

$ slay -TERM user1 user2 user3
$ slay -clean user1 user2 user3
$ pkill -HUP -u user1,user2 programm
$ killall -INT -u user1 programm
  • slay ("schlachten", kill alle Prozesse eines oder mehreren Usern, Paket "slay")
  • pkill (Killt alle Prozesse des gleichen Programms oder User, aus dem Paket "procps")
  • killall (Killt alle Prozesse des gleichen Programms, aus dem Paket "psmisc")

Passwörter generieren (1)

$ makepasswd
024dK9AAea

$ makepasswd --minchars=12 --maxchars=16 --count=2
cwXENNJIe2aX
mRNHaTSAiqGztH

$ apg
Please enter some random data (only first 8 are significant)
(eg. your old password):>
4fleajOubub (FOUR-fleaj-Oub-ub)
NeicjoghAn2 (Neic-jogh-An-TWO)
Tumbech2 (Tum-bech-TWO)
cardAnOoc0 (card-An-Ooc-ZERO)
titBesyoj6 (tit-Bes-yoj-SIX)
ItjugVaf7 (It-jug-Vaf-SEVEN)

Passwörter generieren (2)

$ gpw
foxitivi
edederde
imillsio
sonsestr
esssinne
rlaction
micariqu
tansescr
onaulcif
erwavibu

$ pwgen
edo5Sai3 aet7Gobe OomaiV4W Hoh5Choo Eeghah2e Iem8Thap aya5ieWo fae3Agh6
ahYo4ohv ohGai1qu ahh6uW3a eb0pi2Zo sieKee3g YaeZo1he egieta7H TheiSee3
ohNa4Ne3 aiS1aita yiPo1woo feuJ8fah poe9Ka6I aJicee0Z aengih7Z chooZiu8
Ohxoh6Au ohdeGho8 xae9Vee0 di0ooRei aiL0xoo2 iet4moaF Lee2oame Aefeith8
Ahri2xee WieGh2Wo Oob7KahM eish7Pie Ieyiegh3 Pie5eija ohB6Ahpe xogeeg6B
ieH1oole zeX5Iesh teivah7I vieYo7or aishoo6S AiH2ugei nie0Shei UuPah2ce
Ahzu5iYi bieN3chu Chohcu5e raubee5R xooBee1i Olei8ooz caeth1Oo Ijuajoo7
uthe9teL AiThah4e Fooxoof2 OhNg4zie li9quieX Mae9chae uisaiPh9 Fi0CahPh
eizi0Jed aung9suR oh7Ohviu ue0dei0E Uuc9aesh me1eiZie Rai8paey othiut6O
Mo0aayuo xaeMe4ha eGh6lei3 aeGeu1mo Eiraiph7 yazoXe0y xor2aeK7 Caokoh3n
nae1Aefu cezai6Ev iPhie8hu Ahth9ena quee2Jae toh2Bah6 Aishii6r OaB6Ye7b
us6que3O Iejuc7Zu AhJ9EiZe zahYae2c Ay8shea2 che2bahJ biNaech2 Airei5Mi
Meu0seip iG9Yelei abe7geeK Nohk8loi Phae7hau cooDie1s ot2Shahv jo5hia3R
Ooyaimo6 ecaeVog2 Ooti1iet Nueghaa4 Bex8phoh eeBie6Ge Fie3shiL ThieTh5d
ieZaex9a mui6Iech eud4ieDe jahle9Ma Oobie6Ae ze0uzauP yie6Bied Ahm3ooTe
taid7ooM Hee5aith ahb3IeJ0 aoneiS1o sooNg0gi EeCie7ko Sah7ahl2 sho4johF
Iehah0oo iTheen4u ieghiu5O ge6ahj5O Eibei8ba Oom5deet eeShai7M Di3aosee
neilaeX7 rushu4Re Chah4Se7 cie8meiH ahRish6u ke6Ea4ej Fae7Aez5 quee9Aho
boub5Bej ba4Yiequ daF7lahr rairohM7 sighe1Oo ooR0im8k Aewiw2Ui ivuc6oZ3
iuGhau1i waezo7Ch viph4Lae EibaK0is aiqueeR4 Ru6aa6Tu paet8Weh eeH1hu2f

Farbe auf der Kommandozeile

$ colordiff datei1 datei2  # statt diff
$ colordiff < patch.diff
$ svn diff | colordiff

$ colormake  # statt make
$ colorgcc   # statt gcc

$ grep --color pattern datei

$ tail -f syslog | ccze -A
$ colortail -f syslog
$ lwatch -i syslog
$ tail -f syslog | loco

$ ccal  # statt cal
$ htop  # statt top

Wie teste ich meinen Mailserver?

$ swaks -t abe@noone.org -s sym.noone.org -q RCPT
=== Trying sym.noone.org:25...
=== Connected to sym.noone.org.
<-  220 sym.noone.org ESMTP Postfix (Debian/GNU)
 -> EHLO nemo.deuxchevaux.org
<-  250-sym.noone.org
<-  250-PIPELINING
<-  250-SIZE 10240000
<-  250-ENHANCEDSTATUSCODES
<-  250 8BITMIME
 -> MAIL FROM:<abe@nemo.deuxchevaux.org>
<-  250 2.1.0 Ok
 -> RCPT TO:<abe@noone.org>
<** 450 4.2.0 <abe@nemo.deuxchevaux.org>: Sender address rejected: Greylisted, see http://postgrey.schweikert.ch/help/noone.org.html
 -> QUIT
<-  221 2.0.0 Bye
=== Connection closed with remote host.

Ping auf Drogen

$ fping -a -g 192.33.96.24/29
192.33.96.24
192.33.96.27
192.33.96.28
192.33.96.31
ICMP Host Unreachable from 192.33.96.77 for ICMP Echo sent to 192.33.96.25
ICMP Host Unreachable from 192.33.96.77 for ICMP Echo sent to 192.33.96.26
ICMP Host Unreachable from 192.33.96.77 for ICMP Echo sent to 192.33.96.29
ICMP Host Unreachable from 192.33.96.77 for ICMP Echo sent to 192.33.96.30

$ mtr sym.noone.org

# netselect -vv ftp.de.debian.org ftp2.de.debian.org \
                ftp.ch.debian.org ftp.nl.debian.org ftp.debian.org
Running netselect to choose 1 out of 5 addresses.
.......................................................
ftp.de.debian.org                       25 ms  16 hops   90% ok ( 9/10) [   72]
ftp2.de.debian.org                      17 ms  17 hops   90% ok ( 9/10) [   51]
ftp.ch.debian.org                        0 ms   3 hops   90% ok ( 9/10) [    0]
ftp.nl.debian.org                       22 ms  15 hops   90% ok ( 9/10) [   62]
ftp.debian.org                          22 ms  15 hops   90% ok ( 9/10) [   60]
    0 ftp.ch.debian.org

WebDAV auf der Kommandozeile

$ cadaver https://webdav.phys.ethz.ch/unixhome/abe/vortraege
Authentication required for D-PHYS on server `webdav.phys.ethz.ch':
Username: abe
Password: 
dav:/unixhome/abe/vortraege/> ls
Listing collection `/unixhome/abe/vortraege/': succeeded.
Coll:   wml                                    0  Mar 13  2007
dav:/unixhome/abe/vortraege/> quit
Connection to `webdav.phys.ethz.ch' closed.

Shells parallel bedienen: pconsole

$ pconsole
pconsole WJ101

pconsole command mode
>>> attach /dev/pts/9
attaching /dev/pts/9 : Ok

>>> <Ctrl-D>

Press <Ctrl-A> for command mode
> ls
> <Ctrl-A>

pconsole command mode
>>> quit
detaching from /dev/pts/9 : Ok
$ 

Parallele SSH (1): Skripting (pssh, mussh, dsh)

$ parallel-ssh -l root -h serverliste.txt which inotail
[1] 03:39:55 [SUCCESS] snitch
[2] 03:39:55 [SUCCESS] kiva6
[3] 03:39:56 [FAILURE] metisse Exited with error code 1

$ echo uname -a | mussh -h snitch -h kiva6 -h metisse
Enter your script here.  End with single "." or EOF.
kiva6: Linux kiva6 2.6.26-2-xen-amd64 #1 SMP Thu Feb 11 02:57:18 UTC 2010 x86_64 GNU/Linux
metisse: GNU/kFreeBSD metisse 8.1-1-686-smp #0 Tue Aug 17 23:24:32 CEST 2010 i686 i386 Intel(R) Atom(TM) CPU N270   @ 1.60GHz GNU/kFreeBSD
snitch: Linux snitch 2.6.26-2-amd64 #1 SMP Thu Sep 16 15:56:38 UTC 2010 x86_64 GNU/Linux

$ dsh -m snitch,kiva6,metisse -r ssh -M -- uname -a
snitch: Linux snitch 2.6.26-2-amd64 #1 SMP Thu Sep 16 15:56:38 UTC 2010 x86_64 GNU/Linux
kiva6: Linux kiva6 2.6.26-2-xen-amd64 #1 SMP Thu Feb 11 02:57:18 UTC 2010 x86_64 GNU/Linux
metisse: GNU/kFreeBSD metisse 8.1-1-686-smp #0 Tue Aug 17 23:24:32 CEST 2010 i686 i386 Intel(R) Atom(TM) CPU N270   @ 1.60GHz GNU/kFreeBSD

Parallele SSH (2): Skripting (dish, clustershell)

$ dish -c ssh -e 'uname -a' -p0 snitch kiva6 metisse
spawn ssh snitch uname -a
Linux snitch 2.6.26-2-amd64 #1 SMP Thu Sep 16 15:56:38 UTC 2010 x86_64 GNU/Linux
spawn ssh kiva6 uname -a
Linux kiva6 2.6.26-2-xen-amd64 #1 SMP Thu Feb 11 02:57:18 UTC 2010 x86_64 GNU/Linux
spawn ssh metisse uname -a
GNU/kFreeBSD metisse 8.1-1-686-smp #0 Tue Aug 17 23:24:32 CEST 2010 i686 i386 Intel(R) Atom(TM) CPU N270   @ 1.60GHz GNU/kFreeBSD

$ clush -w 'kiva[1-6]' uname -a
kiva6: Linux kiva6 2.6.26-2-xen-amd64 #1 SMP Thu Feb 11 02:57:18 UTC 2010 x86_64 GNU/Linux
kiva3: Permission denied (publickey,password).
clush: kiva3: exited with exit code 255
kiva4: Linux kiva4 2.6.18-6-xen-vserver-amd64 #1 SMP Sun Feb 21 01:19:17 UTC 2010 x86_64 GNU/Linux
kiva2: Linux kiva2 2.6.26-2-xen-amd64 #1 SMP Thu Feb 11 02:57:18 UTC 2010 x86_64 GNU/Linux
kiva5: Linux kiva5 2.6.26-2-xen-amd64 #1 SMP Thu Feb 11 02:57:18 UTC 2010 x86_64 GNU/Linux
kiva1: Linux kiva1 2.6.26-2-xen-amd64 #1 SMP Wed Mar 10 00:29:48 UTC 2010 x86_64 GNU/Linux

Parallele SSH (3): Interaktiv (clusterssh, mssh)

$ cssh root@server1 root@server2 root@server2

$ mssh root@server1 root@server2 root@server2

Weitere Tools: TakTuk, pexec (auch lokal)

Links

Danke

  • Michael Prokop
  • Ulrich Dangel
  • Nico Schottelius
  • Christoph Berg
  • Carsten Hey
  • Euch fürs Zuhören.