Unix

temporary file descriptor

my_cli_tool --file <(echo "my data here")

ANSI C escaping

From https://dwmkerr.com/quick-tip-sending-newlines-with-curl/

# send headers with newlines
curl http://example.org -H $'Forwarded: host="foo\nbar"'

Basics

Unix är inte svårt. Allting är väldigt logiskt och genomtänkt. För alla kommandon finns det manualsidor du kan läsa på servern genom att skriva man <kommando>. Nedan presenteras de vanligaste kommandona och vad de gör.

Redirecting output

stdout to file:                       my_command >  /path/to/my_file
stdout to file:                       my_command 1> /path/to/my_file
stderr to file:                       my_command 2> /path/to/my_file
stderr and stdout to file:            my_command &> /path/to/my_file
stderr to stdout:                     my_command 2>&1
stdout to stderr:                     my_command 1>&2
stdout to file, stderr to other file: my_command > out 2> err

Simple HTTP server (with Python)

Write to file

cat <<EOF > myfile.txt
multiple
lines
here
EOF
echo "text goes here" | sudo tee myfile.txt

Bash