May 4, 2020 Linux 7 minutes, 5 seconds

This setting allows you to enter shell commands quite efficient. You just enter the first couple of letters of a coomand and press page up/down. The shell tries to auto complete them based on your previous commands.

In /etc/inputrc

# alternate mappings for "page up" and "page down" to search the history
"\e[5~": history-search-backward
"\e[6~": history-search-forward


      - vim
      - emacs
      - strace
      - devel-base

Return a single line string from input yaml

yq -rc '.packages | .[][]' conf.yml | paste -sd' '

systemctl restart nscd

echo "line 1
line 2" >> multiple


cat <<EOT >> multiple
line 1
line 2





useradd -p $(openssl passwd -1 $PASS) $USER

echo "password" | sha1sum

usermod -a -G GROUP USER

sg NEW_GROUP -c "bash"
newgrp NEW_GROUP
newgrp $(id -gn) # ensure membership in own group

Those will create additional login shells!

exec su -l USER_NAME

This will not create an additional login shell but will require the users password. When passwordless sudo is enabled use sudo before su

chown --reference=otherfile newFile
chmod --reference=otherfile newFile

chmod g+s /path/to/parent

groupadd -g ${gid} ${name} && useradd -d /home/${name} -u ${uid} -g ${gid} -m -s /bin/zsh -r ${name} &&\
    echo "${name} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers &&\
  1. Create group, create user with homedirectory, uid/gi, zsh login shell, system account
  2. Add line to sudoers file to allow user passwordless sudo


# Auth with username password and store cookie information
curl -c cookies.txt -X POST -d 'username=admin&password=admin'
# Use cookie auth information to post data from json file
curl -b cookies.txt -d @data.json -H "Content-Type: application/json" -X POST
# Use auth token
curl -H "X-Auth-Token: <Token ID>"


curl -H "Accept:application/json"


curl \
-h "Content-type: application/json" \
-d '{"title": "Test Title", "note": "Test note"}' \

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=OPTION -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

common options for dPDFSETTINGS are:

  • dPDFSETTINGS=/screen lower quality, smaller size.
  • dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs.
  • dPDFSETTINGS=/prepress output similar to Acrobat Distiller "Prepress Optimized" setting
  • dPDFSETTINGS=/printer selects output similar to the Acrobat Distiller "Print Optimized" setting
  • dPDFSETTINGS=/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file

(command1 &) && (command2 &)

ps -o pid,user,%mem,command ax | sort -b -k3 -r

su - targetuser -s /bin/bash -c "/bin/echo hello world" 

grep -v -F -x -f

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf *.pdf

pdfjam --nup 2x3 --frame true --noautoscale false --delta "0.2cm 0.3cm" --scale 0.95

find . -executable -type f

sudo dmidecode | grep BIOS

echo $(curl -ss

route -n | awk '($1 == "") { print $NF }'

ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1
ifconfig eth0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1

# dpkg
dpkg-query -L <PACKAGE_NAME>
dpkg-deb -c <FILE-NAME>
apt-file list <PACKAGE_NAME> (package not installed)

# Pacman
pacman -Ql  <PACKAGE_NAME>

rpm -ql <PACKAGE_NAME>

Basics e.g. modelnumber, manufactorer

dmidecode -t1

Ram slots

dmidecode -t memory

from here

  • zsh always sources '~/.zshenv'.
  • Interactive shells source ~/.zshrc
  • Login shells source ~/.zprofile and ~/.zlogin

  1. Interactive

    Interactive means that the commands are run with user-interaction from keyboard, so the shell can prompt the user to enter input.

  2. Non-interactive

    The shell is probably run from an automated process so it can't assume if can request input or that someone will see the output.

  3. Login

    Means that the shell is run as part of the login of the user to the system. Typically used to do any configuration that a user needs/wants to establish his work-environment.

  4. Non-login

    Any other shell run by the user after logging on, or which is run by any automated process which is not coupled to a logged in user.

ps axo user:20,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,comm

wget \
     --recursive \
     --no-clobber \
     --page-requisites \
     --html-extension \
     --convert-links \
     --restrict-file-names=windows \
     --domains \
     --no-parent \

zip -rP PASSWORD folder/

groupadd GROUP && useradd -g|-G GROUP user
  • lower g when group exists
  • optional -M for no home directory

php -m


type ALIAS

convert -density 384 NAME.svg -define icon:auto-resize NAME.ico

I want to match not just only the program but its arguments (here for entr)

ps ax | grep "xelatex main.tex" | grep -v grep | awk '{print "kill -9 " $1}' | sh

awk -v min=1 -v max=100 'BEGIN{srand(); print int(min+rand()*(max-min+1))}'

This command recursively syncs two folders with advanced matching options I am running for syncing my documents to my eInk Reader.

rsync -rv \
--omit-dir-times \ # ignore timestamps
--prune-empty-dirs \ # don't create emtpy directories
--delete \ # also delete files at the destination
--exclude='dir1' --exclude='dir2' \ # exclude dir1 and dir2
--include='*/' \ # but include all other directories
--exclude='.*' \ # exclude all hidden files
--include='*.pdf' --include='*.epub' \ # include .pdf and .epub files
--exclude='*' \ # exclude all the rest
-e "ssh -p8022" \ # copy over ssh
source \ # source directory to sync
user@host:/destination # target directory on remote

  1. with builtin methods
    watch -n 3 'kill -USR1 $(pgrep "^dd$")'
  2. with package pv
    dd if=/dev/urandom | pv | dd of=/dev/null

    use pv -s 4G for ETA, here approximately 4G

  3. with new status
    dd if=/dev/urandom of=/dev/null status=progress

instead of

grep string1 file1 > result1
grept string1 file2 > result
diff result1 result2 

use <()

diff <(grep string1 file1) <(grep string1 file2)

ndb (network device block) module and qemu-nbd command is required!


for i in "$@"

case $i in
        echo "modprobe nbd, creating device and mounting"
        sudo rmmod nbd
        sudo modprobe nbd max_part=63
        sudo qemu-nbd -c /dev/nbd0 '~/path/to/disk.vmdk'
        echo "Device created"
        if [[ -f /dev/nbd0p1 ]]
            sudo mount /dev/nbd0p1 ~/mounts/tmp
            sudo partprobe /dev/nbd0
            sudo mount /dev/nbd0p1 ~/mounts/tmp
        echo "Mounted at ~/mounts/tmp"
        echo "Unmounting, deleting device and removing nbd module"
        sudo umount ~/mounts/tmp
        sudo qemu-nbd -d /dev/nbd0
        sudo rmmod nbd
        echo "Done"
        echo "invalid option"