Rule 0: Break the rules.
Rule 1: If the terminal was a breakfast cereal, which fun scripts/tips would be on the back?
Rule 2: Ask questions.
Rule 4: No one should need to tesseract your screenshot.
Rule 8: Read one thing and read it well.
Rule 32: echo 'enoemos esirprus' | rev
Rule 64: Show people their mistakes so they can improve.
Rule β: Some things canβt be done in terminal. declare -A arr[β]=16; printf "Rule ${arr[β]}: The last rule is false.\n"
Useful markup:
> Comment block
Comment block
`echo βBasic code blockβ`
echo "Basic code block"
```
#!/usr/bin/env sh
printf βCode block with colorationβ ```
#!/usr/bin/env sh
printf "Code block with coloration"
beautiful. These will go into my βcommands file.β Thatβs a file I keep of cli commands that I donβt need to know every day β but need them from time to time. Itβs just a text file that has the command with a short description. Then occasionally at times when I waiting for something to start, I will just read through the file and keep those commands refreshed. Thanks for the new content.
# Paste inside the "server {" encapsulation:
location /ip {
default_type text/plain;
return 200 $remote_addr;
}
location /ip_json {
default_type application/json;
return 200 "{\"ip\":\"$remote_addr\"}";
}
# Save and exit
sudo systemctl start nginx
curl 0/ip # Test
curl 0/ip_json # Test
sudo systemctl reload nginx # If you need to apply changes
# From your local machine:
curl MY_SERVER_IP_HERE/ip # Test
# Please ask for finer grained instructions.
Itβs Wednesday but Iβve been using the terminal a lot recently to edit mp3 files! I have been using mp3cut to trim up the DLN file system talks from previous episodes. I find this is quicker than using audacity!
It is really nice to have a tool like this and clear documentation that provides example use cases. +1 As you can see from my history, I had to play a bit to get the hang of it
Similar to the next one, this is a GIF of a GIF so expect smoother results.
Cooked up some chafa sprite animation instructions:
# Sprites source: https://www.gameart2d.com/free-dino-sprites.html
wget https://www.gameart2d.com/uploads/3/0/9/1/30917885/freedinosprite.zip
unzip freedinosprite.zip
cd ./png
nano run.sh
# Paste the following:
#!/bin/bash
i=1
while true; do
chafa --clear -size 50 "Walk ($((i++))).png"
if [ $i = 11 ]; then i=1; fi
sleep 0.05
done
# Save
chmod +x ./run.sh
./run.sh
# Hold down Ctrl+C to stop
Train yourself to use chmod u+x instead of chmod +x
chmod +x grants executable rights system wide, chmod u+x just grants rights to the fileβs owner which is usually all you want.
Try it yourself:
# Create files named A, B and C in the current directory
touch ./A ./B ./C
# Observe the initial file rights
ls -la ./A ./B ./C
# Give everyone executable access to A (same as chmod a+x)
chmod +x ./A
# Give just the owner executable access to B
chmod u+x ./B
# Give just the owner and group executable access to C
chmod ug+x ./C
# Observe the new rights
ls -la ./A ./B ./C
# Cleanup
rm ./A ./B ./C
Security Bonus:
Donβt give executable rights to files at all and just run them directly. Examples: bash ./MY_FILE sh ./MY_FILE
#Shell Options
shopt -s autocd # change to named directory
shopt -s cdspell # autocorrects cd misspellings
shopt -s cmdhist # save multi-line commands in history as single line
shopt -s dotglob
shopt -s histappend # do not overwrite history
shopt -s expand_aliases # expand aliases
shopt -s checkwinsize # checks term size when bash regains control
bind "set completion-ignore-case on"
# Custom Alias
# easy resource
alias resource="source ~/.bashrc"
# Easy Open
alias open="xdg-open"
# IP colors
alias ip='ip -br -c'
alias tb='nc termbin.com 9999'
alias termbin=tb
Highlighting a really nice one, thisβll list all the users on the system (from /etc/passwd) in a human readable table.
nano ~/.bashrc
# Paste the following somewhere within:
# lsusers() Repo: https://github.com/terminalforlife/BashConfig/blob/master/source/.bash_functions
# lsusers() License: https://github.com/terminalforlife/BashConfig/blob/master/LICENSE
lsusers(){ #: List users on the system, according to '/etc/passwd'.
printf "%-20s %-7s %-7s %-25s %s\n" "USERNAME" "UID" "GID" "HOME" "SHELL"
local X
while IFS=':' read -a X; do
if [ "$1" == "--nosys" ]; then
# It's possible some users might show up if they mistakenly
# were given a HOME, but '--nosys' should otherwise work.
if [[ ${X[5]/\/home\/syslog} == /home/* ]]; then
printf "%-20s %-7d %-7d %-25s %s\n"\
"${X[0]}" "${X[2]}" "${X[3]}"\
"${X[5]}" "${X[6]}"
fi
else
printf "%-20s %-7d %-7d %-25s %s\n" "${X[0]}"\
"${X[2]}" "${X[3]}" "${X[5]}" "${X[6]}"
fi
done < /etc/passwd
}