Error 

Various aliases and short scripts

351 views
Posted January 18, 2010 at 12:01am in Linux with tags ,

There are some aliases and small scripts I use on a normal basis.

I prefer to just type in the machine I want to ssh to instead of typing ssh in front of it. This chunk of code goes in my ~/.bashrc file and creates an alias for each “Host …” entry in ~/.ssh/config. It checks to see if there is an existing command that matches the Host entry, and alerts you if there is a conflict

# Generate SSH aliases
for host in $(grep ^Host .ssh/config | sed s/Host\ //g); do
  TEMP_CMD=$(which $host)
  TEMP_ALIASES=$(echo "`alias`" | sed 's/alias\ \(.*\)=.*/\1/' | grep ^$host$)
  if [ ${#TEMP_CMD} -gt 0 ]; then
    echo "Alias $host conflicts with command $TEMP_CMD"
  elif [ ${#TEMP_ALIASES} -gt 0 ]; then
    echo "Alias $host conflicts with alias $host"
  else
    alias $host="ssh $host"
  fi
done

When you open a terminal you will see something like this if you have conflicts.

Alias www conflicts with alias www
Alias hg conflicts with command /usr/bin/hg
Alias git conflicts with command /usr/bin/git
[20:05:21] manis@baron:~$


Thing things I need to do on a normal basis with screen is list the sessions, and attach an already attached session. The sdr alias can have a session appended to it, or run by itself if you only have one session.

# Screen Aliases
alias sls='screen -ls'
alias sdr='screen -d -r'

There are a few commands I just think are way too long, these make it a little faster to do things, the alias md5 will make it easier to move back and forth between OS X and Linux.

# Command Shortening Aliases
alias md5='md5sum'
alias sha='sha256sum'
alias p='/usr/bin/python2.5'

Simple ls aliases, should be pretty straight forward.

# ls Aliases
alias lsd='ls --group-directories-first'
alias lsl='ls -l'
alias lsh='ls -lh'
alias ls1='ls -1'

The first alias here, just mounts a given ISO ($1) at mount point ($2). The 2nd is a manual mount for my filer. I didn’t want it automounting since it would give someone access to pretty much everything I have. A quick line count alias, quickie to grep history, and an alias to give me the size of a folder only showing 1 level below. The last alias in this group creates a screen session with the name irssi and executes irssi in side of it, but it also detaches the session. This was created because a lot of times I wanted to start irssi in the background, but didn’t want to have to detach the screen session.

# Various
alias iso='sudo mount -o loop $1 $2'
alias mount.filer='sudo mount host:/dir /dir'
alias lc='wc -l'
alias gh='history | grep'
alias fs='du --max-depth=1 -h'
alias irc='screen -d -m -S irssi /usr/bin/irssi'

This is a short script, that could probably be made into a one line alias. It uses screen to connect to a USB serial adapter. By default it connects at 115200, but the speed can easily be changed… ’s 9600′

#!/bin/bash

if [ $# -ne 1 ]; then
  SPEED=115200
else
  SPEED=$1
fi

screen /dev/ttyUSB0 $SPEED
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Twitter


Leave a Reply