linux ยท reference

Linux HOW-TOs

Bash

Get .ini file value

sed -nr "/^\[protocol.mysql\]/ { :l /^password[ ]*=/ { s/.*=[ ]*//; p; q;}; n; b l;}" /etc/somefile

where protocol.mysql is the section and password is the variable name.

Fancy PS1 prompt

export PS1='[\u@\[\033[41;1m\]\h\[\033[0m\] \W(openstack_$OS_TENANT_NAME)]\$ '

dont forget to add \[ \] around control codes or cursor position will be wrong

Misc

Youtube-DL shortcuts

Bandcamp

youtube-dl -o "%(playlist_title)s/%(autonumber)02d - %(title)s.%(ext)s"

Dump all formats

youtube-dl -F URL

Download one or many formats (mix)

youtube-dl -f 251 URL   # Audio only
youtube-dl -f 278+251 URL   # Audio + video
youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' URL
youtube-dl -f 'bestvideo[height<=480]+bestaudio[ext=m4a]/best[height<=480]' URL

.xscreenrc

hardstatus alwayslastline
hardstatus string '%{= Kd} %{= Kd}%-w%{= Kr}[%{= KW}%n %t%{= Kr}]%{= Kd}%+w %-= %{KG} %H%{KW}|%{KY}%101`%{KW}|%D %M %d %Y%{= Kc} %C%A%{-}'
defscrollback 5000
startup_message off
shell /bin/bash

Screensaver

Rename mate-screensaver-commandto .orig and symlink xscreensaver-command to mate-screensaver-command. Rename mate-screensaver to .orig. Edit exec section in /etc/xdg/autostart/mate-screensaver.desktop and change it to

Exec=/usr/bin/env http_proxy=http://127.0.0.1:3128 xscreensaver -no-splash

Least annoying screensavers: grav, bsod (-no-nvidia), starwars, glsnake, apple2, glmatrix, substrate, cubicgrid, loop, phosphor.

Text-mode Linux: add consoleblank=60 to kernel boot to blank screen in 60 seconds.

Cups sharing

Add yourself to lpadmin group. Tick “Share printers connected to this system”. When configuring your printer, also share it.

Laptop-server

/etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="consoleblank=60"

/etc/hdparm.conf:

spindown_time = 244

Fonts

Check actual pixel order on the screen and configure in Appearance settings

Copy Windows 7 Segoe UI fonts to /usr/share/fonts/truetype/win7

Install terminus font to /usr/share/fonts/truetype/terminus from https://files.ax86.net/terminus-ttf/ Run

dpkg-reconfigure fontconfig
OR
fc-cache -f

Openssl

Generate CApath manually (c_rehash utility replacement to re-index all certificates):

for f in *pem; do hash=$(openssl x509 -noout -hash -in $f); ln -s $f ${hash}.0; done;

Windows-related

Change domain password

Pick Domain controller from the list using

dig -t srv _ldap._tcp.dc._msdcs.[domain_name]

then

smbpasswd -U DOMAIN/username -r ip_of_domain_controller

Dmesg alias for Windows (cygwin .bashrc)

Use windows psTools from sysinternals:

dmesg () { /cygdrive/c/apps/pstools/psloglist64.exe -s -t '\t' |sort -k1 -n | awk -F '\t' '{print $6" "$1" "$4" "$2" "$7" "$9;}'; }

Show Windows License Key

wmic path softwarelicensingservice get OA3xOriginalProductKey

System scan / verification

sfc /scannow

Restore Health

dism /online /cleanup-image /restorehealth

Windows 10 enable Hyper-V

Run in Powershell as admin:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V
Published:
comments powered by Disqus