Einzeiler
Aus VDR Wiki
Version vom 12. Mai 2007, 19:59 Uhr von Hulk (Diskussion | Beiträge)
Inhaltsverzeichnis |
Einzeiler / Schnippsel
SPLIT
split -b 95b xxxxxxxxxxx.tar.gz xxxxxxxxxxx.tar.gz.split.
cat xxxxxxxxxxx.tar.gz.split.* > xxxxxxxxxxx.tar.gz
tar xvzf xxxxxxxxxxx.tar.gz
FIND/LS
ls -lahS $(find / -type f -size +10000k)
find /video -follow -type d | grep -vEe ".(rec|del)$"
find /cdrom/ -name *.deb -exec cp -v '{}' /var/cache/apt/archives ';'
find / -type d -exec du -sh {} \; > /tmp/dirsizes.lst
SED/EUMULATION
cat | sed ':'
cat -s | sed '/./,/^$/!d'
tac | sed '1!G;h;$!d'
grep | sed '/patt/!d'
grep -v | sed '/patt/d'
head | sed '10q'
head -1 | sed 'q'
tail | sed -e ':a' -e '$q;N;11,$D;ba'
tail -1 | sed '$!d'
tail -f | sed -u '/./!d'
cut -c 10 | sed 's/\(.\)\{10\}.*/\1/'
cut -d: -f4 | sed 's/\(\([^:]*\):\)\{4\}.*/\2/'
tr A-Z a-z | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
tr a-z A-Z | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
tr -s ' ' | sed 's/ \+/ /g'
tr -d '\012' | sed 'H;$!d;g;s/\n//g'
wc -l | sed -n '$='
uniq | sed 'N;/^\(.*\)\n\1$/!P;D'
rev | sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'
basename | sed 's,.*/,,'
dirname | sed 's,[^/]*$,,'
xargs | sed -e ':a' -e '$!N;s/\n/ /;ta'
paste -sd: | sed -e ':a' -e '$!N;s/\n/:/;ta'
cat -n | sed '=' | sed '$!N;s/\n/ /'
grep -n | sed -n '/patt/{=;p;}' | sed '$!N;s/\n/:/'
cp orig new | sed 'w new' orig
SED
Einzelne Zeilen einer Datei können mit dem Kommando sed gelöscht werden.
Das folgende Beispiel demonstriert, wie die erste, die letzte bzw.
die zweite bis vierte Zeile aus einer Datei gelöscht werden.
sed -e '1d' file
sed -e '$d' file
sed -e '2,4d' file
sed -n '4p' file
sed -i "1a ..........."
sed -i "1i ..........."
CUT/TR
cut -c 12-18 # die Zeichen 12 bis 18 jeder Zeile
cut -f 2 -d ' ' # das 2.Feld, Feldtrenner ist ' '(blank)
tr -s '[:blank:]' # sqeeze meherere blanks-> ein blank
tr -d ' ' # alle blanks löschen
ZIP
gzip file.diff [*.diff] | führt zu file.diff.gz
bzip2 -kv file.diff [*.diff] | führt zu file.diff.bz2
tar cvIf dir.bz2 dir/* | alle files in dir
WC/Emulation
stringZ=abcABC123ABCabc
echo ${#stringZ}
INFO
awk '{ print $3 }' /proc/version
awk '/model name/ {print $4}' < /proc/cpuinfo
awk '/model name/ { print"" $4" "$5" "$6 }' < /proc/cpuinfo
awk '/cpu MHz/ { print "MHz " $4 }' < /proc/cpuinfo
awk '{ print "Kernel "$3 }' /proc/version
cat /proc/interrupts
cat /proc/net/dev
cat /proc/pci
lspci -v
uname
lsmod
dmesg
SCREEN
import -window root screen-`date "+%Y-%m-%d_%H:%M:%S"`.png
DATE
sh | date +%s
perl | perl -le 'print time'
awk | awk 'BEGIN {print systime()}'
SUBSTITUTION
a=/a/b/c/d
b=b.xxx
csh bash result
---- -------- ------
$a:h ${a%/*} /a/b/c
$a:t ${a##*/} d
$b:r ${b%.*} b
$b:e ${b##*.} xxx
${VAR#pattern} removes the shortest matching pattern, anchored at
the beginning of the string.
${VAR##pattern} removes the longest matching pattern, anchored at
the beginning of the string.
${VAR%pattern} removes the shortest matching pattern, anchored at
the end of the string.
${VAR%%pattern} removes the longest matching pattern, anchored at
the end of the string.
${VARIABLE:-${WERT}} Nutzt den Wert von Variable. Falls die Variable nicht gesetzt ist, wird der Wert benutzt.
${VARIABLE:=${WERT}} Nutzt den Wert von Variable. Falls die Variable nicht gesetzt ist, wird der Wert benutzt, und Variable erhält den Wert.
${VARIABLE:?${WERT}} Nutzt den Wert von Variable. Falls die Variable nicht gesetzt ist, wird der Wert ausgegeben und die Shell beendet.
Wenn kein Wert angegeben wurde, wird der Text parameter null or not set ausgegeben.
${VARIABLE:+${WERT}} Nutzt den Wert, falls die Variable gesetzt ist, andernfalls nichts.
EXPANSION
juergen@anna:~> line="foo bar cutoff baz cutoff fuz"
juergen@anna:~> text='cutoff'
juergen@anna:~> echo "${line#*$text}"
baz cutoff fuz
juergen@anna:~> echo "${line##*$text}"
fuz
ssh
ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N ""
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ""
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ""