Cheat sheet of various unrelated commands

Obtain public ip address

When you need to find out your public IP address, there are a plethora of options available. You can simply search for it, but thanks to OpenDNS there’s also a very quick command-line friendly method available.

dig +short myip.opendns.com @resolver1.opendns.com

apt

Reverse dependencies

To see, which packages depend on a given package:

apt-cache rdepends <package>

Checking reverse dependencies is especially useful when you want to know, which installed packages require given package:

apt-cache rdepends --installed <package>

Unsupervised installation

When installing packages, apt(8) tends to prompt for questions every now and then. Unattended installation can be forced with:

DEBIAN_FRONTEND=noninteractive apt-get --yes \
  -o Dpkg::Options::="--force-confdef" \
  -o Dpkg::Options::="--force-confold" install <packages>

Find out packages of a repository

To find out, which packages are available from a repository, and might be installed from there, see files /var/lib/apt/lists/*_Packages.

inotify

If you want to run a command every time a file changes, following loop should serve your needs:

while inotifywait -e MOVE_SELF "$1"; do
  sleep 0.333
  ...
done

Artificial delay (i.e. sleep) may not be required, but in many cases it seems to make things more reliable. Replace $1 with filename you are monitoring, and ... with any payload.

gpg-agent with ssh

If gpg or ssh fails without prompting for secret key passphrase, check the following:

  • Your gpg-agent.conf should have correct configuration. In this example ssh support is enabled and pinentry is used for passphrase prompts:

      enable-ssh-support
      pinentry-program /usr/bin/pinentry
    
  • (If applicable.) Use update-alternatives to point the pinentry symlink to suitable program (e.g. /usr/bin/pinentry-curses).

  • Make sure environment variable GPG_TTY is set.

      export GPG_TTY=$(tty)
    
  • After logout/login (or equivalent circumstances) your need to refresh the agent:

      echo UPDATESTARTUPTTY | gpg-connect-agent