A place where I store different command-line shortcuts and other things I reference often.
Determine the what program is listening on a per-port basis (requires sys-apps/net-tools)
-p may need root to look up the process name
netstat -ltnp | grep -w ':80'
Alternatively (requires sys-apps/iproute2):
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.
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:
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:
vim +585 base/package.use.mask
vim can also be used to directly open a certain function or word by searching, for example,
vim +/get_bootparam /lib/gentoo/functions.sh
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:
Disable python2_7 targets
*/* PYTHON_TARGETS: -python2_7
- Always create and activate a virtual environment before installing modules via pip.
- Always use python -m pip instead of simply pip command.
- Never execute pip as root/super user permissions (do not use sudo or doas).
Creation and activation:
mkdir project && cd project
python -m venv venv
. venv/bin/activate # Activate, or alternatively: `source venv/bin/activate`
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?
python -m pip install git+https://github.com/maffblaster/sheen.git@<commit-id>
Or via a tarball:
python -m pip install git+https://github.com/maffblaster/sheen/archive/<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:
bundler install # Pulls the dependencies
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).
Merged into the bash article (emacs section).