30 technical tips and tricks to speed query, report, and dashboard performance
Simple tricks to speed you up on the command line
-
Upload
janos-gyerik -
Category
Technology
-
view
136 -
download
0
description
Transcript of Simple tricks to speed you up on the command line
![Page 1: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/1.jpg)
time-saving trickson the command line
![Page 2: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/2.jpg)
$ cd /usual/path/to/work/on/projectx$ screen -R projectx$ tail -f my.log
ctrl-a c$ less config.sh
gimme a new window
Hm... what's in config.sh?Gimme a new window!
![Page 3: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/3.jpg)
gimme a new windowgimme a new windowgimme a new windowgimme a new windowgimme a new window
$ tail -f /some/logctrl-a c$ less /some/filectrl-a c$ man some_docctrl-a c
gimme another window
ctrl-a is the command keyc stands for create window
![Page 4: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/4.jpg)
ctrl-a nctrl-a pctrl-a w
Next windowPrevious windowWindow list
next prev window
C-a p C-a n
C-a p C-a n
![Page 5: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/5.jpg)
detach/reattach
I want to get out!
I want to go back!
Terminal crashed!
My sessions?
# detach
ctrl-a d# reattach
$ screen -R label # detach and reattach
$ screen -R label -D
$ screen -ls
![Page 6: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/6.jpg)
ctrl-a ?
![Page 7: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/7.jpg)
search history with ctrl-r
...I want that for loop I used a while ago...
ctrl-r and type "for"
ctrl-r again...
ctrl-r again...
$ history | grep for 362 for i in *; do mv "$i" "$(echo $i | iconv -f iso8859-1 -t us-ascii//translit)" -v; done 364 for i in *; do mv "$i" "$(echo $i | iconv -f utf-8 -t us-ascii//translit)" -v; done
(reverse-i-search)`for': history |grep for
(reverse-i-search)`for': for i in *; do mv "$i" "$(echo $i | iconv -f utf-8 -t us-ascii//translit)" -v; done
(reverse-i-search)`for': for i in *; do mv "$i" "$(echo $i | iconv -f iso8859-1 -t us-ascii//translit)" -v; done
![Page 8: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/8.jpg)
ctrl-w
ctrl-k
ctrl-y
ctrl-c
Delete last word
Delete until line end
Paste deleted stuff
Cancel entire line
editing quickly
![Page 9: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/9.jpg)
ctrl-a
ctrl-e
Jump to line start
Jump to line end
moving quickly
ctrl-a a inside screen
![Page 10: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/10.jpg)
man bashSearch for: "READLINE"
"Commands for Moving""Commands for Changing Text"
![Page 11: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/11.jpg)
/error
n
N
g
G
Search for "error"
Next match
Previous match
Jump to first line
Jump to last line
moving quickly in less
![Page 12: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/12.jpg)
m a
' a
-i
:n
Mark line in register "a", "b"
Jump to register "a", "b"
Toggle case sensitive search
Go to next file
moving quickly in less
m b
' b
![Page 13: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/13.jpg)
h
![Page 14: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/14.jpg)
mail it to me# mail me the relevant stuff
$ grep stuff /var/log/messages | mailx -s "stuff from logs" [email protected]# mail me the whole file
$ uuencode /var/log/messages messages.txt | mailx -s "system logs on $HOST" [email protected]
![Page 15: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/15.jpg)
# after the loooong task, mail me
$ rsync --progress /disk1/iso/* /disk2/iso/; ls -lha /disk2/iso/ | mailx -s "copy isos done" [email protected]
mail me when finished
![Page 16: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/16.jpg)
# infinite loop until file appears and then mail me
$ while :; do date; test -f file.txt && break; sleep 300; done; ls -lh file.txt | mailx -s "file appeared" [email protected]
mail me when file appears
![Page 17: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/17.jpg)
# infinite loop until matching line appears and then mail me
$ while :; do date; grep pattern /path/to/log && break; sleep 300; done; { date; grep -B50 -A50 pattern /path/to/log; } | mailx -s "log snippet" [email protected]
mail me when log matches
![Page 18: Simple tricks to speed you up on the command line](https://reader034.fdocuments.net/reader034/viewer/2022050817/55619badd8b42ae27d8b59c4/html5/thumbnails/18.jpg)
$ openssl des3 < secret.bin > secret.bin.des3enter des-ede3-cbc encryption password:Verifying - enter des-ede3-cbc encryption password:$ openssl des3 -d < secret.bin.des3 > decrypted.binenter des-ede3-cbc decryption password:$ cmp secret.bin decrypted.bin$ # empty output means the two files are identical
encrypt and decrypt simply