Shell-Oneliner
Based on https://github.com/onceupon/Bash-Oneliner but mainly for ZSH, my personal needs and configuration.
Terminal Tricks
Ctrl + r : begins a backward search through command history.(keep pressing Ctrl + r to move backward)
Ctrl + a : move to the beginning of line.
Ctrl + e : move to the end of line.
Ctrl + w : cut the word before the cursor; then Ctrl + y paste it
Ctrl + u : cut the line; then Ctrl + y paste it
Ctrl + x + Ctrl + e : launch editor defined by $EDITOR to input your command. Useful for multi-line commands.
Esc + c : converts letter under the cursor to uppercase, rest of the word to lowercase.
... with my own configuration
Ctrl + t : print current date
environment variables
$0 : name of shell or shell script.
$1, $2, $3, ... : positional parameters.
$# : number of positional parameters.
$? : most recent foreground pipeline exit status.
$- : current options set for the shell.
$$ : pid of the current shell (not subshell).
$! : is the PID of the most recent background command.
$USER : current username
$HOSTNAME : current hostname
length of variable
var="some string"
echo ${#var}
# 11
replace
foo=tachchen
echo ${foo/a/-}
# t-chchen /0,0s
echo ${foo//c/-}
# ta-h-hen
Math
prime factors
factor 50
# 50: 2 5 5
Sed
sed 1d filename # remove first line
sed 1,100d filename # remove line 1-100
Description