Table of Contents

Shell Tricks

Hotkeys (bash)

Alt + .
Esc, .
Add last argument of most recent command.
Ctrl + A
Ctrl + E
Jump to start or end of the line.
Ctrl + D Disconnect / exit current shell

Snippets

do something with multiple files

You can use find and the -exec option.

For example if you want to extract multiple .rar files:

find . -name '*.rar' -exec 'unrar' 'e' '{}' \;

{} gets replaced with the filename found by find . -name '*.rar'. Watch out that you have to single-quote (') every option to the program you're -executing.

open multiple files in image viewer

for file in *.jpg; do feh $file&; done

The & makes it run in the background and opens all files at once.

urlencode text

echo "text" | jq -sRr @uri

(source)

compare md5sum with given string

md5sum -c - <<<"b4460802b5853b7bb257fbf071ee4ae2 file_name.ext"

generate 4 letter password

shuf -n 4 /usr/share/dict/ngerman

mount partition from dd image

losetup --partscan --find --show sd.img
lsblk | grep loop
mount /dev/loop0p2 sd/

ssh without executing .login

ssh -t user@host /bin/bash

generate crypt(3) output for /etc/shadow

mkpasswd # on debian
openssl passwd -crypt myPassword

convert ext2/ext3 to ext4

tune2fs -O extents,uninit_bg,dir_index,has_journal /dev/sdx0

backup MBR (Master Boot Record)

# Use 446 bytes to overwrite or restore your /dev/XYZ MBR boot code only with the contents of $mbr.backup.file.
# Use 512 bytes to overwrite or restore your /dev/XYZ the full MBR (which contains both boot code and the drive’s partition table) with the contents of $mbr.backup.file.
dd if=/dev/sdx of=mbr.img bs=512 count=1

check & wipe drive

badblocks -t random -wsv /dev/disk/by-id/drive-id

compare the contents of two folders

diff -rq dir1 dir2

login with empty password

passwd -d USERNAME
usermod -U USERNAME

disable gnome-keyring in favor of ssh-agent

chmod 0 /usr/bin/gnome-keyring-daemon

hide process informations from other users

mount -o remount,rw,hidepid=2 /proc

save current X.org config

sudo X :2 -configure

find out current Kernel boot options

cat /proc/cmdline

similar sites