Random Linux notes

There is a lot of stuff I end up wanting to refer to later. I’m putting some here.

Set caps as ctrl

Doing it this way seems to work across the console and X:

Edit /etc/default/keyboard and set:

XKBOPTIONS=ctrl:nocaps

If you already have XKBOPTIONS set, append ctrl:nocaps to its existing value using a comma for separator, e.g.:

XKBOPTIONS="terminate:ctrl_alt_bksp,ctrl:nocaps"

Should be effective after next reboot or issuing the setupcon command.

macOS

rando

# list directory sizes
$ du -sh *

# count all occurrences of a string in a directory
$ grep -roh lorem . | wc -w

# watch a remote log
$ ssh user@server "tail -f /var/log/apache2/error.log"

# Create directories a through z inside log/users/, creating any parent directories that don't exist yet too.
$ mkdir -p log/users/{a..z}

# brace expansion example
$ mkdir -p drupal/sites/all/modules/{contrib,custom,patched,features}

# launch program and ditch so term can be closed
$ <command> & disown

# df with posix mode, don't make 80 columns wide
$ df -hP

cat <file> | tee output.txt | grep <term>

- grep -r -i somethingtosearchfor ./
- pgrep - search processes
- ngrep - monitor network activity

splitting files

# Split a file called largefile into 1 gigabyte pieces called split-xaa, split-xab, split-xac ...
$ split -b 1G verylargefile split

# Join the splits back together
$ cat split-xaa split-xab split-xac > rejoinedlargefile

# Here is a way to join the files together with brace expansion. Be mindful of filenames and order.
$ cat split-xa{a,b,c} > rejoinedlargefile

OpenBSD

Caps Lock as Control
# wsconsctl keyboard.map+="keysym Caps_Lock = Control_L"
To make this run at boot, add keyboard.map+="keysym Caps_Lock = Control_L" to /etc/wsconsctl.conf.

Thinkpad Specific

Battery Threshold
In Windows use lenovo Vantage to set maximum battery at 80% to preserve battery life. In Linux write to
/sys/class/power_supply/BAT0/charge_stop_threshold
and
/sys/class/power_supply/BAT0/charge_start_threshold
Can also use TLP with the tp-smapi kernel module (tp-smapi-dkms package in debian, for example)
You can let tlp take care of that for you like so:

~ ❯❯❯ egrep "BAT[0,1]" /etc/tlp.conf
# auto = mid on BAT, high on AC.
START_CHARGE_THRESH_BAT0=75
STOP_CHARGE_THRESH_BAT0=80
START_CHARGE_THRESH_BAT1=75
STOP_CHARGE_THRESH_BAT1=80

~ ❯❯❯ sudo systemctl restart tlp

   egrep "BAT[0,1]" /etc/tlp.conf
Works like a charm. I put the TLP config in /etc/tlp.d instead though.
Thinkpad Trackpoint

Edit the file

/etc/tmpfiles.d/tpoint.conf

Add the lines:

w /sys/devices/platform/i8042/serio1/speed - - - - 255
w /sys/devices/platform/i8042/serio1/sensitivity - - - - 255
w /sys/devices/platform/i8042/serio1/inertia - - - - 6
w /sys/devices/platform/i8042/serio1/press_to_select - - - - 0

May need to use

/sys/devices/platform/i8042/serio1/serio2
instead

To make changes take effect before next reboot:

sudo systemd-tmpfiles --prefix=/sys --create

fio - flexible io tester

fio is a tool for testing disk speed. It is probably easiest to use with the included job files in the examples directory. You can also use --showcmd= to extract the commands from a job file. However here are a few sample commands:

# random write test
sudo fio --name=randwrite --ioengine=libaio --iodepth=1 --rw=randwrite --bs=4k --direct=0 --size=512M --numjobs=2 --runtime=240 --group_reporting

# random read test
sudo fio --name=randread --ioengine=libaio --iodepth=16 --rw=randread --bs=4k --direct=0 --size=512M --numjobs=4 --runtime=240 --group_reporting

# read write performance test
sudo fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=random_read_write.fio --bs=4k --iodepth=64 --size=4G --readwrite=randrw --rwmixread=75

rsync

/usr/local/bin/rsync --info=progress2 --modify-window=1 -rltvh --no-perms /var/run/importcopy/tmpdir/dev/da3p1/ /mnt/storpool/share

rsync -essh -rtpvz rocks. Really, there’s nothing more to say. Learn it. Use it. Love it. Here’s a good rsync anecdote: in my last job, I worked on a project that was doing daily (and sometimes more-than-once-per-day) builds of a 100 MB installer. Near the end of the release cycle, we were putting each daily build on a private web server for the client to download and test. Uploading the entire build took over a hour on my capped DSL line. It turns out that the fastest way to do this is to ssh into the server, duplicate yesterday’s build to a file with today’s date, then rsync today’s build up to the server. rsync magically figures out which parts of the installer have changed (usually not more than a few KB) and synchronizes the build in under a minute. I have no idea how it does that. I read once that it was somebody’s PhD project. Thank God for smart people.