Shell
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 -e -
add 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 ~/.profile - for 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 ~/.profile - for 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 changes -
0;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– Normal -
1– Bold (bright) -
2– Dim -
4– Underlined
The second number indicates the color you want:
| color | background | text |
|---|---|---|
| black | \e[0;40m | \e[0;30m |
| Red | \e[0;41m | \e[0;31m |
| Green | \e[0;42m | \e[0;32m |
| Brown | \e[0;43m | \e[0;33m |
| Blue | \e[0;44m | \e[0;34m |
| Purple | \e[0;45m | \e[0;35m |
| Cyan | \e[0;46m | \e[0;36m |
| Light gray | \e[0;47m | \e[0;37m |
output redirection
-
2>&1redirect StdErr to StdOut -
2>&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 zsh - Oh-My-ZSH
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" - install font for "powerlevel10k" https://github.com/romkatv/powerlevel10k#meslo-nerd-font-patched-for-powerlevel10k
-
choose font
Meslo Nerdin preferences of the terminal or editor - install "powerlevel10k"-theme for ohmyzsh https://github.com/romkatv/powerlevel10k
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k - Set
ZSH_THEME="powerlevel10k/powerlevel10k"in~/.zshrc.-
sed -i '/ZSH_THEME="/c\ZSH_THEME="powerlevel10k/powerlevel10k"' ~/.zshrc
-
- Type
p10k configureif the configuration wizard doesn't start automatically.
edit for visual studio code
- Press
command+shift+Pin your VSCode window. - type
settings.jsonand open it. - insert:
{ ... "terminal.integrated.fontFamily": "MesloLGS NF", "terminal.integrated.defaultProfile.linux": "zsh" ... }