Post

Miscellaneous commands I always forget

Miscellaneous commands I always forget

Some commands I use so rarely that every time I need them I have to go look them up again. Noting them here so I don’t lose them.

See who’s using a port

1
lsof -n -i4TCP:8081

Replace 8081 with the port you want to investigate. -n avoids hostname resolution (faster). The output shows the process, PID, and user listening on that port.

Cut a video segment with ffmpeg

1
ffmpeg -i video_original.mp4 -ss 00:58:00 -t 00:00:15 -c copy video_cortado.mp4
  • -ss 00:58:00 → starts at 58 minutes
  • -t 00:00:15 → duration of 15 seconds
  • -c copy → copies the streams without re-encoding (fast and lossless)

Useful for extracting clips or creating samples from long videos.

Identify the distro from a script

When you’re in a script and need to know which distro you’re running on:

1
awk -F= '$1=="ID" { print $2 ;}' /etc/os-release

Returns something like arch, ubuntu, debian, manjaro. You can use it in conditionals:

1
2
3
4
5
6
7
DISTRO=$(awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)

if [ "$DISTRO" = "arch" ]; then
    pacman -S --needed pacote
elif [ "$DISTRO" = "ubuntu" ]; then
    apt install -y pacote
fi

Bonus: close the lid without suspending

If you use your laptop as a server and don’t want it to suspend when you close the lid:

1
2
3
4
5
6
7
sudo nvim /etc/systemd/logind.conf
# add:
# HandleLidSwitch=ignore

sudo nvim /etc/UPower/UPower.conf
# add:
# IgnoreLid=true

Useful for leaving the laptop processing something with the lid closed.

This post is licensed under CC BY 4.0 by the author.