interesting ports (MacPorts)

  • HandBrake – MPEG tool
  • hexfiend – hex editor
  • macfuse, sshfs – user space file systems
  • textmate2 – text editor
  • wget

unzip all zip files in the current dir to a separate folder

<br />
for file in `ls *.zip`; do unzip $file -d `echo $file | cut -d &quot;.&quot; -f 1`; done<br />

linux :: add a new hdd

e.g. /dev/sdb

partition disk:

fdisk /dev/sdb
new partition: key n
primary partition: key p
partition 1
default values
write: key w

format disk:
mkfs -t ext3 /dev/sdb1

edit /etc/fstab accordingly

convert between character sets on linux

to convert a file from utf-16 to utf-8 you can use recode (make a copy of the file first!):

recode UTF16..UTF8 myFile.txt

diff two folders on OSX

<br />
diff -qr &quot;path/to/first/dir&quot; &quot;/path/to/second/dir&quot; | grep -v -e 'Thumbs' -e 'DS_Store' | sort &gt; diff.txt<br />

openvpn resolv.conf

<br />
sudo rm /etc/resolv.conf<br />
sudo ln -s /etc/resolvconf/run/resolv.conf /etc/resolv.conf<br />

selecting a random file in the current folder

<br />
#!/bin/bash<br />
files=(*)<br />
echo &quot;${files[RANDOM % ${#files[@]}]}&quot;<br />

using grep and xargs

open all files that contain “/sdk/” for edit:
grep -Rl "/sdk/" . | xargs p4 edit

replace all occurences of /sdk/ with /new_sdk/
grep -Rl "/sdk/" . | xargs sed -i "s#/sdk/#/new_sdk/#g"

reindex avi

if your avi index is corrupt, you can use a tool included in MPlayer (on OSX: sudo port install MPlayer)

mencoder -idx corruptAvi.avi -ovc copy -oac copy -o ReIndexedAvi.avi

replace non ascii chars in file names

for filename in *.xml; do newname=`echo $filename | tr -cd '\11\12\15\41-\176'`; mv "$filename" "$newname"; done