commands I don’t want to forget (but often do…)

Safety First

Copying and pasting the code samples below can be dangerous. I recommend not copying and pasting as the root or administrative user.

$ shell

# recursively search for "date" in files, and output date combined with filename
grep -r -T date * | awk -e '/date/{ print $3 "-" $1 }' | sort -r | sed 's/://'
# does the same as above, then prints out files that do not contain "date"
grep -r -T date * | awk -e '/date/{ print $3 "-" $1 }' | sort -r | sed 's/://'; echo;  grep -L -r -T date *
# for all files in current directory, change spaces to dashes
for file in ./*; do; mv "$file" "${file// /-}"; done
# for all files in current directory, change uppercase to lowercase
for f in `./*`; do mv -v "$f" "`echo $f | tr '[A-Z]' '[a-z]'`"; done
# mount hardrive as rw
sudo mount -t ntfs-3g -o uid=pi,gid=pi /dev/sda1 /media/USBDRIVE/
# view packages by size
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
# remove uninstalled packages from dpkg
dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge
qemu-system-x86_64 -m 4G -enable-kvm -drive file=img1.cow,format=qcow2 -vga qxl -device virtio-serial-pci -device virtserialport[0/125]
v=spicechannel0,name=com.redhat.spice.0 -chardev spicevmc,id=spicechannel0,name=vdagent -spice unix,addr=/tmp/vm_spice.socket,disable-ticketing

remote-viewer spice+unix:///tmp/vm_spice.socket

: vim

" don't add comments on new lines
set formatoptions-=ro

" don't hide markup characters
set conceallevel=0
" remove trailing whitespace
" silently remove trailing whitespace from all open buffers
bufdo %s/\s\+$//e | update
" does the same removal as above, but silently restores position in buffer (and retabs)
let currBuff=bufnr("%") | let save_pos = getpos(".") | silent bufdo %s/\s\+$//e | silent retab | update | execute 'buffer ' . currBuff | call setpos('.', save_pos) | noh
" add !important to css color values
%s/#[0-9a-z]*/\0 !important/