System

Determining which Debian/Ubuntu release your are running

$ lsb_release -r

Or for more information:

$ lsb_release

Determining which Unix you are running

$ uname

Or,

$ uname -a

Configuring system swappiness

Swappiness is a number between 0 and 100 that regulates how much the system uses the swap file. I like setting this value to 0 to keep my apps as responsive as possible. Create a file /etc/sysctl.d/local.conf and add this line:

vm.swappiness = 0

If you want to set the value for the current session only:

echo 0 > /proc/sys/vm/swappiness

Hardware information

For information about the hardware attached to your system, check out:

Using Smartctl, Smartd and Hddtemp on Debian

Report hard disk usage

So you might want to know how much data a process reads or writes to a hard disk. You can monitor process total disk utilisation with the 'iotop' command. Run 'iotop' and then press 'a' for --accumulated.

Updating config files

If you get given a new config file called new.conf and you want to integrate it with your old config file old.conf then:

$ cp old.conf updated.conf
$ merge -A updated.conf new.conf old.conf

Then go through and edit updated.conf resolving all the merge errors, picking and choosing what to update and what to keep. When you're done copy updated.conf to old.conf so it becomes the new config file.

Changing 2 space indent to 4 space indent (e.g. for python files)

Recording and replaying a macro

To record a macro press 'q' and then a number between 1 and 9. E.g. press "q1". The macro is now recording. When you've finished issuing your commands press 'q' again to finish recording. To replay a macro press '@' followed by the number of the macro. That is, if you pressed "q1" to record the macro, press "@1" to replay the macro. To replay the last macro again press "@@".

Deleting to end of line

d$

Deleting to beginning of line

d^

Finding text

To search forward for "text":

/text

To search backward for "text":

?text

To repeat the last search in a forward direction press 'n', or to search again backwards press 'N'.

Finding and replacing text

To replace the first instance of "search" on the current line with "destroy":

:s/search/destroy/

To replace all instances of "search" on the current line with "destroy":

:s/search/destroy/g

To replace all instances of "search" on lines 13 to 37 with "destroy":

:13,37 s/search/destroy/g

To replace all instances of "search" in the entire file with "destroy":

Books I've read

C++ blogs/articles

C++ performance tips

++c can be faster than c++.

use const for everything that you possibly can.

use 'inline' when you need to define a function in a header. Typically only do that if it's small and the increase in code size from inlining is worth the cost to avoid the cost of a function call. For anything except trivially small functions you'll probably need to profile to know if it's worth it.

systemd

systemd is an init system used in most Linux distributions to bootstrap the user space and manage all processes subsequently.

Following a service log

e.g. for bind9:

# journalctl -f -u bind9

or for everything:

# journalctl -f

System status

To see spawned services hierarchy:

# systemctl status

Or for a specific service e.g.:

# systemctl status networking

SaltStack

Running a command on specified minions

salt 'host' cmd.run 'update-locale'

Running a command on all minions

salt '*' cmd.run 'update-locale'

Listing active jobs

salt-run jobs.active

Listing available grains

salt 'example' grains.items

Listing available pillar

salt 'example' pillar.items

Reporting a grain value

e.g. for the 'mem_total' grain:

salt '*' grains.item mem_total

KDE

Running user login script (X11/XOrg/XWindows)

A way to run user login scripts which works for KDE Plasma (and apparently other X.Org Server X Window System environments) is to create a *.desktop file in ~/.config/autostart/. For example I have a ~/.config/autostart/ssh-add.desktop file with the following contents to register my SSH key in the SSH Agent: