From Gentoo Wiki
Jump to:navigation Jump to:search

A place where I store different command-line shortcuts and other things I reference often.


Software engineering



Determine the what program is listening on a per-port basis (requires sys-apps/net-tools)

Note: -p may need root to look up the process name

user $netstat -ltnp | grep -w ':80'

Alternatively (requires sys-apps/iproute2):

user $ss -ltnp '( sport == :80 || sport == :443 )'


When attempting to connect to a resource outside of an organization's network, tunnels are an indispensable part of the equation. These can be produced using various utilities, which depends upon the OS being run, if the user has administrative access to the workstation (which is unlikely in a secure environment), if the OS permits mounting/attaching USB block storage devices, etc.

Windows OS


Stuff is based off this serverfault thread.

Modern versions of putty (download here) can open tunnels on a Windows system.

Grep and open with Vim

grep and vim commands can be used in conjunction to search for specific lines in files and open the files to those files to the lines desired:

user $grep -rsin "emacs.*cairo"
base/package.use.mask:585:app-editors/emacs:25 cairo
base/package.use.mask:586:app-editors/emacs:26 cairo

Open vim to line 585:

user $vim +585 base/package.use.mask

vim can also be used to directly open a certain function or word by searching, for example,

user $vim +/get_bootparam /lib/gentoo/

XDG_RUNTIME_DIR for commands over ssh

Running systemctl --user commands via ssh generally fails because the XDG_RUNTIME_DIR environment variable is not set to the user's run directory. Here's one workaround:

user $ssh larry@hostname
user $export XDG_RUNTIME_DIR=/run/user/${UID}
user $systemctl --user



Disable python2_7 targets

FILE /etc/portage/package.use/python
*/* PYTHON_TARGETS: -python2_7

Virtual environments


  1. Always create and activate a virtual environment before installing modules via pip.
  2. Always use python -m pip instead of simply pip command.
  3. Never execute pip as root/super user permissions (do not use sudo or doas).

Creation and activation:

user $mkdir project && cd project
user $python -m venv venv
user $. venv/bin/activate # Activate, or alternatively: `source venv/bin/activate`
user $python -m pip install <package> # Install dependencies

User install via pip hacks

Can the following be used to easily reinstall Portage (and friends) from gitweb.g.o?

user $python -m pip install git+<commit-id>

Or via a tarball:

user $python -m pip install git+<tarball_release_name>.tar.gz

Running ruby programs

Sometimes it is necessary to download dependencies through language specific package managers, such as bundler in the following example. Navigate to the directory containing the Gemfile (generally the repo's base dir), and run:

user $bundler install # Pulls the dependencies
user $bundler exec <prog name>

Note that this will avoid installing dependencies through Gentoo's package manager, which is an unhelpful side affect, but this work around may be necessary for some software (such as Jekyll).

Bash shortcuts

Merged into the bash article (emacs section).