22 July 2006

A helicopter ride over London

Went on a helicopter ride last weekend, there were some great views. Here are some photos, click on each photo to see it in more detail:

12 July 2006

xargs and find

find /srv/files -name "Thumbs.db*" -print0 | xargs -0 /bin/rm -f {}

This deletes all files matching pattern Thumbs.db*. -print0 and -0 cause delimitation by the null char rather than whitespace, so filenames can contain whitespace.

If you add -i to the xargs options the command will be called once for each entry rather than receiving a list of entries, e.g :

find . -name "${pattern}" -print0 | xargs -0 -i convert -verbose -quality ${compression} {} {}

Note, with -i {} can be repeated multiple times in-place of the entry.

10 July 2006

Favourite Firefox extensions

Adblock Plus
Copy Plain Text
Delicious Bookmarks
Download Statusbar
Febe (I'm still looking for a decent profile sync other than file sync)
Foxmarks Bookmark Synchronizer
IE Tab
Search Marker
Web Developer

Updated (24/06/2008)

09 July 2006

Check disks with e2fsck

umount /dev/hdc1
/sbin/e2fsck -c -c -C 0 -D /dev/hdc1

-c -c: marks bad blocks using a non-destructive read-write test
-C 0: prints completion bar

Find world writeable/executable or suid/sgid files

# Find suid/sgid files
find / -type f \( -perm -04000 -o -perm -02000 \) \-exec ls -lg {} \;

# Find world writable files
find / -type f \( -perm -002 \) -exec ls -lg {} \;

# Find world executable files
find / -type f \( -perm -001 \) -exec ls -lg {} \;

# Find unowned files
find / -nouser -o -nogroup

Copy directories over ssh

cd /somedir/somesubdir && tar cpzf - * | ssh somehost "cd /somedir/somesubdir && tar xpzf -"


ssh somehost "cd /somedir/somesubdir && tar cpzf - *" | (cd /somedir/somesubdir && tar xpzf -)

cd/dvd iso files

# make an iso of a dir
mkisofs -r /home/sekhonp/ > image.iso

# make an iso of a cd
dd if=/dev/cdrom of=image.iso bs=10k

# mount iso
mount -o loop,ro -t iso9660 ./image.iso /mnt/iso

# burn an iso to cd
cdrecord -v speed=12 dev=0,0,0 -data image.iso
# or directly
mkisofs -r /home/sekhonp/ | cdrecord -v speed=12 dev=0,0,0 fs=8m -data -

Find the disk usage hog

#Top 20 disk usage hogs on /home
cd /home; du -cks * | sort -nr | head -20


lsof is a very useful diagnostic command:

# show whose listening on sockets
lsof -i -P

# which processes are using a file
lsof /mnt

# which process is holding localhost:80
lsof -i TCP:80

# show handles associated with a process 30563
lsof -p 30563

# show handles associated with a process syslogd
lsof -c syslogd

# show files associated with user sekhonp
lsof -u sekhonp

Grab photos off your mobilephone via bluetooth using obexftp

List photos on phone
obexftp -b 00:1A:75:F1:40:B5 -c "Memory Stick/DCIM/100MSDCF" -l
Grab photos off phone
obexftp -b 00:1A:75:F1:40:B5 -c "Memory Stick/DCIM/100MSDCF" -g DSC00024.JPG

quick ssh script

Create a script called ssh-to like so:
ssh `basename $0` $*
>ln -s ssh-to server1

now to ssh to server1 all you need type is

you can also run commands on server e.g
>server1 ls -al

cvs update all subdirectories

assuming server1.domain.com:/cvs is the cvs repository and you have a whole bunch of cvs modules checked out in /cygdrive/c/sekhonp/it/builds/system1


 echo "Updating system ${1}"
 cd ${1}

 for module in *; do
   if [ -d ${module}/CVS ]; then
     ${cvs} -qq -d :pserver:`whoami`@server1.domain.com:/cvs update -dPA ${module}

update /cygdrive/c/sekhonp/it/builds/system1

unhide shortcuts in windows

attrib /S /D -H "C:\Documents and Settings\All Users\Start Menu\*"

Script to download a tar and extract it if it has changed


export http_proxy=${proxy}

cd ${downloadDir}

modificationTime=`stat -c %y ${tarFile}`
wget -N --proxy=on --proxy-user=${1} --proxy-passwd=${2} --http-user=${3} --http-passwd=${4} ${sourceTarFile}
newModificationTime=`stat -c %y ${tarFile}`
echo "old modification time: ${modificationTime}, new modification time: ${newModificationTime}"

if [ "${modificationTime}" != "${newModificationTime}" ] ; then
echo "Extracting ${tarFile}..."
tar -C ${extractDir} -xzvf ${tarFile} 1>/dev/null

Syncing directories on windows

Here's a little script that syncs a directory using xxcopy

@echo off
REM /BI Backs up incrementally, different (by time/size) files only.
REM /FFn Treats file times within +/- n sec as the same
REM /ZY Deletes extra files or subdirectories in destination, there is no confirmation prompt.
REM /E Copies directories and subdirectories, including empty ones.
REM /H Copies hidden and/or system files also.
REM /R Overwrites read-only files.
REM /KS Keeps the source attributes including the read-only bit.
REM /ZE Disables the use of all Environment Variables for XXCOPY.
REM /YY No prompting
REM /C Continues copying even if errors occur (default).
REM /Q Does not display files which are skipped.
REM /oA append to log file
REM /X excludes files or directories, e.g.

xxcopy "E:\sekhonp\it\builds\bats-system\" "C:\sekhonp\it\builds\bats-system\" /BI /FF30 /ZY /E /H /R /KS /ZE /YY /C /Q /Xclasses\ /X*\classes\ /Xdecompiledsrc\ /X*\dist\ /X*\build\ /Xlog\ /X*.zip