Shell scripting
cheatsheets:
bash basics
conditions
- check if file exists:
[ -f /path/to/file ] && do something if [ -f /path/to/file ]; then do something; fi
find biggest folders of current directory
du -hs * | sort -rh | head -5
default text editor
for inline shell call:sudo EDITOR=nano crontab -eadd to~/.bashrcor~/.zshrc:export EDITOR=nano
for default root editor, edit also/root/.bashrcor/root/.zshrc
echo "export VISUAL=nano\nexport EDITOR=nano" >> ~/.bashrc
echo "export VISUAL=nano\nexport EDITOR=nano" >> ~/.zshrc
sudo sh -c "echo -e \"export VISUAL=nano\nexport EDITOR=nano\" >> ~/.bashrc"
sudo sh -c "echo -e \"export VISUAL=nano\nexport EDITOR=nano\" >> ~/.zshrc"
login message:
for local user edit:nano ~/.profilefor global:/etc/profileor/etc/bashrc(only for bash shell)
add for example:
#shell login message
echo -e "\n\n You are working on: \t\e[41m>>> welding-shop.fronius.com <<<\e[49m\n\n"
custom shell prompt:
for local user edit:nano ~/.profilefor global:/etc/profileor/etc/bashrc(only for bash shell)
add for example:
#shell login message
alias PS1="\e[0;32m[\u@\h \w]\$ \e[0m"
\u- user\h- host\w- current path
[test@ubuntu1 ~]$ <- in green
PS3 for select prompt
https://www.thegeekstuff.com/2008/09/bash-shell-take-control-of-ps1-ps2-ps3-ps4-and-prompt_command/
Terminal colors
\e[0;32m\e[– Begin color changes0;32m– Specify the color code[\u@\h \W]\$– This is the code for your normal BASH prompt (username@hostname Workingdirectory $)\e[0m– Exit color-change mode
The first number in the color code specifies the typeface:
0– Normal1– Bold (bright)2– Dim4– Underlined
The second number indicates the color you want:
output redirection
2>&1redirect StdErr to StdOut2>&1 |redirect and Pipe, same as|&(not in sh)
|| visible in terminal || visible in file || existing
Syntax || StdOut | StdErr || StdOut | StdErr || file
==========++==========+==========++==========+==========++===========
> || no | yes || yes | no || overwrite
>> || no | yes || yes | no || append
|| | || | ||
2> || yes | no || no | yes || overwrite
2>> || yes | no || no | yes || append
|| | || | ||
&> || no | no || yes | yes || overwrite
&>> || no | no || yes | yes || append
|| | || | ||
| tee || yes | yes || yes | no || overwrite
| tee -a || yes | yes || yes | no || append
|| | || | ||
|& tee || yes | yes || yes | yes || overwrite
|& tee -a || yes | yes || yes | yes || append
zsh
install zsh
ZSH (shell with more features)sudo apt install zshorsudo dnf intall zsh(on Fedora)
Oh-My-ZSHsh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Oh My Zsh Cheatsheet
install powerlevel 10k theme
install font for "powerlevel10k"https://github.com/romkatv/powerlevel10k#meslo-nerd-font-patched-for-powerlevel10kchoose fontMeslo Nerdin preferences of the terminal or editorinstall "powerlevel10k"-theme for ohmyzsh https://github.com/romkatv/powerlevel10kgit clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10kSetZSH_THEME="powerlevel10k/powerlevel10k"in~/.zshrc.sed -i '/ZSH_THEME="/c\ZSH_THEME="powerlevel10k/powerlevel10k"' ~/.zshrc
Typep10k configureif the configuration wizard doesn't start automatically.
edit for visual studio code
Presscommand+shift+Pin your VSCode window.typesettings.jsonand click "Open User Settings (JSON)" it.insert or add:{ "terminal.integrated.fontFamily": "MesloLGS NF", "terminal.integrated.fontSize": 12, "terminal.integrated.defaultProfile.linux": "zsh" }
powerline
sudo add-apt-repository universe
sudo apt install --yes powerline
sudo nano ~/.bashrc
# Powerline configuration
if [ -f /usr/share/powerline/bindings/bash/powerline.sh ]; then
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
source /usr/share/powerline/bindings/bash/powerline.sh
fi
änderungen sofort anwenden: source ~/.bashrc
copy default file to config home
mkdir -p ~/.config/powerline
cp -R /usr/share/powerline/config_files/* \
~/.config/powerline/
edit color file: sudo nono ~/.config/powerline/colors.json
#zu rot navigieren und froniusred hinzufügen
"froniusred": [1, "ed1c24"],
sudo nano ~/.config/powerline/colorschemes/default.json
powerline-daemon --replace
terminal emulator
terminator
install:sudo apt install terminator
documentation
Create more terminals by:horizontal split:Ctrl-Shift-overtical split:Ctrl-Shift-e
Shift focus to:next terminal:Ctrl-Shift-nprevious terminal:Ctrl-Shift-p
New tab:Ctrl-Shift-tNew window:Ctrl-Shift-iClose terminal or tab:Ctrl-Shift-wor right mouse click -> Close
Close window with all it's terminals and tabs:Ctrl-Shift-qReset zoom:Ctrl-0