Here are some random notes that I find useful. I also tend to forget and use as reference.
[] Vim reference
:e filename (open filename)
:q! (quit, don’t save)
:x (write if changed, otherwise exit)
a (insert after)
A (insert after line)
h j k l (left, down, up, right)
$ (move to end of line)
^ or 0 (move to beginning of line)
G (move to end of file)
:n (move to “n” line, n=number)
x (delete to the right)
X (delete to the left)
D (delete to the end of line)
dd (delete current line)
yy (yank/copy current line)
V (begin highlight, up and down to select “y” to yank selection)
vn (yank “n” lines below cursor, n=number)
p (put/paste)
u (undo)
/string (search for “string”)
n (search for next string match)
:s/yellow/green/gc (replace yellow with green, g is for global, each match is replaced in a line, instead of the first match in a line. c is for confirm/ask)
:%s/yellow/green/g (replaces yellow with green on the entire page)
:s:/usr/local/bin:/opt/users/bin:g (use something other than / as delineation so you don’t have to escape “/”. Like this nasty example: :s/\/usr\/local\/bin/\/usr\/loca\/bin)
[] find command
find . -name “name” -exec [command goes here] {} \;
find . -type d -exec chmod 750 {} \;
find . -type f -exec chmod 760 {} \;
find /home/BACKUP -mtime +14 -exec rm -fr {} \;
-mtime options:
n exactly n days
+n more than n days
-n less than n days
to convert all backslash \ to forward slash /
find . -type f -iname *.xml -exec sed -i ‘s:\\:/:g’ {} \;
[] Rename multiple files
remove space from all files ending in .mp3
rename ‘s/ //’g *.mp3
rename all files ending in .ZIP to .zip
rename ‘s:\.ZIP:\.zip:’ *.ZIP
[] Sending mail with telnet:
telnet hostname 25
helo me
mail from:myaddress@mydom.com
rcpt to:youraddress@yourdom.com
data
This is a test
.
(thats a newline [enter] – period – and another newline [enter])
[] Fix MBR for windows
http://ms-sys-free.sourceforge.net/
from gnulinux:
ms-sys -m /dev/hda
from msdos or nt recovery console:
fdisk /mbr
[] Batch and snippets (yuck)
http://www.allenware.com/icsw/icswidx.htm
echo Cleanup .bak files older than 7 days
forfiles /p d:\backup /m *.bak /d -7 /c “cmd /c del /q @path”
echo Set variable date as yyyymmdd
set date=%date:~-4,4%%date:~4,2%%date:~-7,2%
echo %date%
[] Filesystem stuff
make image of sda
dd if=/dev/sda of =sda.img bs=1M
backup mbr
dd if=/dev/sda of=mbr.backup bs=512 count=1
mount image
losetup /dev/loop0 sda.img
mount /dev/loop0 /mnt
xfs filesystem and xfsprogs
Determine the amount of fragmentation on sda2
xfs_db -c frag -r /dev/sda2
Filesystem re-organizer, by default, with no arguments. It re-organizes files in mounted partitions for 2 hours. Use -t to change the time.)
xfs_fsr
[] Recover Files
testdisk (recover lost partitions)
photorec (part of the testdisk suite)
foremost sda.img
-t (type doc,jpg,exe etc. all is default)
-a (no error detection, recovers partial files)
-d (indirect block, use for nix filesystems)
-o (output dir)
-T (timestamp output dir)
[] KVM Virtualization
Interface config for bridging to virtualized client /etc/network/interfaces
auto eth0
iface eth0 inet dhcp
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_stp off
bridge_maxwait 5
[] KVM with Windows
The best way to get virtio is on install. Download the block driver floppy image and attach it, I use virt-manager. Set your hard drive to type virtio and start your windows install. It will will prompt you to press f6 to install third party drivers. Then press S (you have a disk from a third party manufacturer, your floppy image)
If you already have a disk type IDE and want it to be virtio (better). Then do this:
1. Create a temporary image
kvm-img create -f qcow2 temp-virtio.img 1G
2. Shutdown your virtual machine and attach temp-virtio.img as a hard drive, as type virtio.
3. Attach the virtio-win-x.x.x.vfd (i used the one from fedoraproject.org, see below) to you virtual machine
4. Boot up and install the drivers
5. Shutdown, remove the old hard drive image and re-add it as type virtio
6. Boot up and since you already installed the drivers it will boot. Otherwise, you get BSOD..
(You can remove the temp-virtio.img and floppy image).. All done.
For network drivers.. Shutdown, set the “device model” to virtio. Attach the NETKVM-xxxx.iso as a cdrom. Bootup and install drivers. yay!
virtio network drivers, quamranet
http://sourceforge.net/projects/kvm/files/kvm-driver-disc/
virtio block device drivers (aka, hard drive)
http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/bin/ or
http://sourceforge.net/projects/kvm/files/kvm-guest-drivers-windows/
[] Windows Policy
run gpedit.msc to edit policy
to backup or move to new host, copy the following
%systemroot%\system32\GroupPolicy\Machine and User dirs
to apply changed policy’s
gpupdate /force
[] RDP tricks
SeamlessRDP http://www.cendio.com/seamlessrdp/
rdesktop -A -s “c:\seamlessrdp\seamlessrdpshell.exe c:\program files\internet explorer\iexplore.exe” -u username -p password hostname
[] Self Signed certificate on debian, the easiest way possible
make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/ssl/private/hostcert.crt
This script will ask for a domain and write the certificate.