Skip to content

Linux Tips

while loop

while true; do ./exec.sh; sleep 10; done

Heredoc

Send a block of text to a command via standard input

Using cat

1
2
3
4
cat <<EOF > file.txt
line 1
line 2
EOF

Note, this write to file.txt. Use >> file.txt to append

But this doesn't work well with sudo - so better use tee

Using tee

1
2
3
sudo tee /etc/file.conf > /dev/null <<EOF
data
EOF

xarg with awk

J'suis une flemme:

kubectl get deployment  -n default --no-headers | awk '{print $1}' | xargs -r kubectl delete deployment -n default

tmux

How to enable logging in tmux?

To log tmux pane output to a file, use the pipe-pane command with a shell command that redirects to a file. i

Start logging current pane

Ctrl+b 
:pipe-pane -o "cat >> ~/tmux-log.txt"

Stop logging

Ctrl+b
:pipe-pane

Log with timestamp in filename

Ctrl+b 
:pipe-pane -o "cat >> ~/tmux-$(date +%Y%m%d-%H%M%S).log"

USB to Serial Adapter on MacOS

On macOS you basically need to (1) find the serial device file under /dev, then (2) attach with screen.

1. Plug in the USB–serial adapter and identify the device

Open Terminal and run:

ls /dev/tty.* /dev/cu.*

Then unplug the adapter, run the same command again, and compare. The new entries that disappear/appear when you plug/unplug are your adapter, typically named like:

  • /dev/tty.usbserial-XXXX
  • /dev/tty.usbmodemXXXX
  • /dev/tty.SLAB_USBtoUART
  • /dev/tty.wchusbserialXXXX

The /dev/tty. or /dev/cu. version both work; I usually use /dev/tty.*.

If nothing new appears, you likely need a driver for the adapter chipset (FTDI, Prolific, Silicon Labs, etc.) from the vendor, then repeat the check above.

2. Connect with screen

Once you know the device, connect to the router console like this:

screen /dev/tty.usbserial-XXXX 9600

Replace:

  • /dev/tty.usbserial-XXXX with your actual device path
  • 9600 with the router’s serial speed (common values: 9600, 19200, 38400, 57600, 115200; many routers use 9600 or 115200)

3. Exiting screen

To quit screen cleanly:

  1. Press Ctrl + A
  2. Then press \ (backslash)
  3. Confirm with y if prompted