Malicious enjoyment derived from observing someone else’s misfortune
 

Tag Archives: bash

Telling bash to step aside for zsh

So, let’s say that you want to change your shell to zsh, but fall back to bash if it isn’t available on whatever system you’re using. This is useful if you use something like NIS or LDAP with home directory NFS, since you’ll be sshing around and bringing your .bashrc with you everywhere. The solution is pretty simple – just add this to the bottom of your .bashrc: hash zsh 2>&- && exec zsh Update: This breaks X-windows. Need to [...]

1,000,000th Fibonacci Number One-Liner in C

This is possibly the best one-liner I’ve ever written: gcc -x c -o /tmp/out – -lgmp

Putting Non-YouTube Videos in MxTube

So, you have your Jailbroken iPod Touch or iPhone with 2.0 firmware running OpenSSH, and you have MxTube 1.5 or better, of course. What if you want one of those pesky videos that YouTube deletes all the time, like Paris Hilton For President? Or maybe you want a full movie on your iPod without having to sync to iTunes since you’re stuck in Linux Land. Well, here’s how.

Putting Images on the iPod Touch from Linux

Idea I wanted to put images on my iPod Touch without using iTunes since, as most of us know, there is no good way to use it from Linux. It turns out there is a magic directory on the iPod Touch where it saves images from Safari. I simply looked at how it saved them, and applied it on my box here at home. Requirements Jailbroken iPod Touch (I used WinPWN), with OpenSSH installed and working (the root password is [...]

Renaming Files Sequentially with BASH

I made a cool one-liner in bash today that renames files sequentially. Here’s an example that takes all the JPEGs in a directory and renames them in order: EII=4; for i in *.jpg; do ls $i; \ NEWNAME=IMG_00`printf “%02d” $EII`.JPG; \ echo Renaming $i to $NEWNAME; \ mv $i $NEWNAME; EII=`expr $EII + 1`; done Pretty cool, huh? This is in relation to my next post. Keep watch…

DNS for bash

Today, I decided I wanted a network service that propagated variables and aliases to every login shell that subscribed to it. This is dangerous on a large scale, but perfectly acceptable on my small home network where everyone trusts everyone else. First, I got Camping installed, bringing back fond memories of Ruby development. I then copied off the blog example, and created TreeHugger, a 427 line script that provides a web interface to edit the variables, and a plain text [...]

Calculating Averages from a CSV with Perl

Code Here’s a quick one-liner using some UNIX utilities and Perl to construct some nice averages from CSV data: for i in `seq 2 20`; do cat crim_rate_2005_by_state.csv | cut -d , -f $i | perl -e ‘$c=$d=0;$e;while(<>){if(/^\d/){$c+=$_;$d+=1}else{s/\s{2,}/ /g;s/”//g;chomp($e=$_);}} print $e, “: “, $c/$d, “\n”‘; done And now, the spaced out version: #!/bin/bash for i in `seq 2 20`; do cat crim_rate_2005_by_state.csv | \ cut -d , -f $i | \ perl -e ‘$c=$d=0; $e; while(<>){ if(/^\d/){ $c+=$_; $d+=1 } [...]

Linux command line tips and tricks

This awesome page told me about the <<< operator in bash. It rocks. It also told me the best way to set an initial login password: umask u=rw,go= openssl rand -base64 6 | tee -a PasswordFile | passwd –stdin joe chage -d 0 joe Also, there’s ssh-copy-id: Usage: /usr/bin/ssh-copy-id [-i [identity_file]] [user@]machine

GNU Screen’s hardstatus

I use GNU Screen. A lot. I found an article linked from DIgg today that showed me how to use a setting called hardstatus to set the little bar at the bottom to my liking. I decided to mess around with it a bit, and I ended up with this: It shows my hostname, IP, uptime, screen window number and name, date and time, and load averages. Pretty cool, huh? This is how you do it: First, create a .screenrc [...]

Using seq to zero-pad strings in a series

I thought this was pretty cool: for i in `seq -f "%03g" 1 100`; do wget http://www.gozerog.com/images/Hawking_$i.jpg; done We were trying to do this the other night using bash, but to no avail since the square brackets only work for local file path expansion. I should have remembered seq. Also, this example shows how to 0-pad a series using seq and bash, noted by the *-f* option. Three cheers for seq!