Shell Commands with Patterns / Wildcards http://www.guckes.net/talks/workshop.regex.txt 2007-10-10 Mi Latest change: Wed Oct 10 03:00:00 CEST 2007 = Aufgaben einer Shell = ! * Wildcard substitution in file names (pattern matching) * Background processing * Command aliasing * Command history * File name substitution * Input and output redirection * Piping * Shell variable substitution hier nur: ! * Wildcard substitution in file names (pattern matching) = Wildcards = Wildcards: ? matches a single character (regex: ".") * matches any string - including null string! (regex: ".*") Sets: [...] a "set" - matches the list of enclosed characters [!...] a "complement set" - matches all characters other than those listed Classes: [[:class:]] characters class, ie one of these: alnum alpha blank cntrl digit graph lower print punct space upper xdigit = echo = echo * objekte mit extension ".c": echo *.c "*" passt auch auf das leere wort: echo A* -> A ABC.doc Arbeitslosenversicherungsbeitrag.txt echo ? a b c X Y Z = ls = ls -l * ls -l *.txt ls -l foo*.txt ls -l *foo* ls -ld dir* ls -l {a,b}.txt ls -l {a,b,c,d}.txt ls -l {a,b,c,d}*.txt ls -l {abc,bcdefg,foo}*.txt ls -l [aeiou]*.txt ls -l [bcdfghjklmnpqrstvwxyz]*.txt ls -l [^aeiou]*.txt ls -l [b-df-hj-np-tv-z]*.txt [a-zA-ZäöüßÄÖÜ] [[:alpha:]] [-aeiou] sonderbedeutung aufheben: \* \? = misc = chmod 644 *.jpg 421421421 110100100 rw-r--r-- grep wort *.txt grep $muster *.txt grep '[aeiou][nks]' *.txt ak ek ik ok uk an en in on un as es is os us mv subdir/* . less *.txt scp file... user@host:dir/ scp /etc/host* /etc/prog/* user@host:backup/ = mmv = Morning has broken.mp3 Morning_has_broken.mp3 mmv '* *' '#1_#2' fuer objekte mit mehreren leerzeichen sind erneute anwendungen noetig. MMV1='mmv '\''img_????.jpg'\'' '\''img_2#1#2#3#4.jpg'\' MMV2='mmv '\''IMG_????.JPG'\'' '\''img_2#1#2#3#4.jpg'\' mmv 'img_????.jpg' 'img_2#1#2#3#4.jpg' mmv 'IMG_????.JPG' 'img_2#1#2#3#4.jpg' img_????.jpg img_2#1#2#3#4.jpg img_123.jpg img_22345.jpg img_0815.jpg img_20815.jpg IMG_4711.JPG img_24711.jpg = Variablen = files=`ls -1 | wc -l` echo $files 23 = History = !! !$ !* !-2 !prefix ls -l `!!` ls -l $(!!) $ echo $(( 5*60*60 + 42*60 + 23 )) 20543 $ factor `!!` factor `echo $(( 5*60*60 + 42*60 + 23 ))` 20543: 20543 $ ls -l a.doc b.txt c.mpg $ rm -f !* $ !ssh = Zsh = readable files: ls -l *(.R) non-executable files: ls -l *(.^X) list 10 new/old files only: alias llfnew='ls -rtl *(.) | tail ' alias llfold='ls -tl *(.) | tail ' a legal command substance: alias lsd='ls -ldF *(/)' example: cd /etc; lsd files with capital letters only: alias lAZ='$PAGER [A-Z]*' apply only to subdirs: alias dusch='du -sch' example: dusch *(/) recursion: chmod 644 **/*(.^R) spaces to underscores: zmv '* *' '$f:gs/ /_' inline expansion von mustern: $ rm -f **/*.txt(TAB) = Links = Shell Command Language http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html Variable and File Name Substitution in the Bourne Shell http://www.unet.univie.ac.at/aix/aixuser/usrosdev/var_file_name_subst_bourne.htm#A27991222 more: Basic Unix Shell Commands http://bobcares.com/article35.html Six useful shell commands for web developers http://muffinresearch.co.uk/archives/2006/10/16/ six-useful-shell-commands-for-web-developers/ Advanced Bash-Scripting Guide http://tldp.org/LDP/abs/html/index.html THPXRF EOF