Friday, September 19, 2008

Symbol Scanner and .bashrc for fast system navigation via the command line terminal

Howto fast command line system navigation via alias' in your ~/.bashrc and a symbol barcode scanner

Here are some alias you can set in your ~/.bashrc
Make sure to remove wrap where necessary and source your bashrc(sbrc) in every terminal that hasn't already loaded your modification. I will update alias' as I go. To have as a reference for you and me. pixelbeat.org/cmdline.html, also has a nice cmdline reference. I though this would come in handy for someone. I made a barcodes cheat sheet, use it if you are to lazy to type. You can also make your own cheatsheet and pass it on to your best buddies with your bashrc :) Enjoy.

Note: You may need to type/scan sudo before some of these alias'.

append to file: .bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
export HISTCONTROL=ignoredups
# ... and ignore same sucessive entries.
export HISTCONTROL=ignoreboth

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
;;
*)
;;
esac

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

#if [ -f ~/.bash_aliases ]; then
# . ~/.bash_aliases
#fi

# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ] && [ -x /usr/bin/dircolors ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
#alias dir='ls --color=auto --format=vertical'
#alias vdir='ls --color=auto --format=long'

#alias grep='grep --color=auto'
#alias fgrep='fgrep --color=auto'
#alias egrep='egrep --color=auto'
fi

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
alias ll='ls -CF'
alias l='ls -la'
alias cpr='cp -r'
#reverse dig
alias digx='dig -x'

alias lso='sudo lsof -i -T -n'

#outguess will only hide data in jpg files
#gout super_secret_pass data.txt poop.jpg fat_poop.jpg
function gout() { outguess -k $1 -d $2 $3 $4 ;}

#scan for open dns resolver ports 1024-1150
function scandns() { nmap -sU -vv -p 1024-1300 -P0 -T Aggressive ;}

#sslsniff listenport cerificatefile
function sslsniffer() { sslsniff -p $1 -c $2 ;} #listenport certfile post_only -P

#ipforwarding on
function ip_forward() { echo 1 > /proc/sys/net/ipv4/ip_forward ;}

function arpsp() { arpspoof -i $1 -t $2 $3 ;} #eth0 victim router
function arpskr() { arp-sk -r -S $1 -D $2 ;} #router victim

#ipt_ssl listenport
function ipt_ssl() { iptables -t nat -A PREROUTING -p tcp --destination-port 443 -j REDIRECT --to-ports $1 ;}

#ungout super_secret_pass fat_poop.jpg data.txt
function ungout() { outguess -k $1 -r $2 $3 ;}

#steghide will hide data in bmp,jpg,au and wav files, default encrypt method is Rijndael/AES 128 bits
#steg poop.jpg fat_poop.jpg data.txt super_secret_pass
function steg() { steghide embed -cf $1 -sf $2 -ef $3 -p $4 ;}

#unsteg fat_poop.jpg
function unsteg() { steghide extract -sf $1 ;}

#unalias vars
function unal() { unalias "$@" ;}

#fsn 192.168.1 255
function fsn() { for i in `seq $2`;do ping -c1 $1.$i;done ;}
alias hc='hexcat'
#awk find replace file
function awkfpf() { awk -F "|" '{gsub( /$1/,"$2");print}' $3 ;}

#ec "modified something in /etc, now commit with bzr"
function ec() {
ec_var="`pwd`" && cd /etc/ && sudo bzr commit -m "$@" && cd $ec_var
}
#dump /dev/mem file.dump 18384 48 4
function memdump() { sudo dd if=$1 of=$2 bs=$3 skip=$4 count=$5 ;}
#macch eth0 00:11:22:33:44:55
function macchange() { ifconfig $1 hw ether $2 ;}
alias ifc='ifconfig'
alias cmd0='sudo'
alias nbrc='nano ~/.bashrc'
alias sbrc='source ~/.bashrc'
alias sudh='sudo dhclient'
alias dush='sudo du -sh' #location
alias agi='sudo apt-get install'
alias agu='sudo apt-get update'
alias ags='sudo apt-cache search'
alias agsh='sudo apt-cache show'
alias agr='sudo apt-get remove'
alias agd='sudo apt-get dist-upgrade'
alias agc='sudo apt-get clean'
alias agac='sudo apt-get autoclean'
alias pkgstat='dpkg --status'
alias pkgrec='sudo dpkg-reconfigure'
alias cdrec='cdrecord -v dev=/dev/cdrom' #*.iso
alias screenl='screen -ls'
alias screenr='screen -raAD'
alias screenk='screen /dev/ttyUSB0 115200'
alias enc='encfs.sh' #mount encfs mounts
alias unc='uncfs.sh' #unmount encfs mount
alias zipit='zip -r' #zip_file.zip file_or_dir_to_zip
alias tarit='tar -czvf' #file_to_make.tar.gz file_or_dir_to_tar
alias tarlit='tar -cvhf' #file_to_tar.tar.gz file_or_dir_to_tar
alias untar='tar -zxvf' #file_to_unpack.tar.gz
alias unrare='unrar e' #file.rar #unpack/open rar
alias unrarl='unrar l' #file.rar # list contents
alias unrarx='unrar x' #file.rar #extract full path
alias unrarp='unrar e -p' # file.rar #unrar password protected rar archive
alias unrart='unrar t' #file.rar # test integrity of archive
alias burncd='cdrecord -v dev=/dev/cdrom' #iso_to_burn.iso
alias npv='pkill npviewer.bin' #this kills flash player
alias killit='killall -v -HUP' #inetd
alias bat='cat /proc/acpi/battery/BAT0/state'
alias t='tail -n'
alias c='cat'
alias p='python'
alias e='encfs'
alias m='mysql -u root -p'

function dumpsql() { mysqldump -h $1 -u $2 -p -r $3 $4 ;} #somehost someuser backup_filename database_name

# '{}' gets replace by the name of the file that was found
function findexi() { find $1 -iname $2 -exec $3 '{}' \; ;} # 'dir' 'file_str' 'str_to_find'
function findex() { find $1 -name $2 -exec $3 '{}' \; ;} # 'dir' 'file_str' 'str_to_find'

function findnam() { find $1 -type f -iname $2 ;} #. "*str_to_find_in_filename*"
function findstr() { find $1 | xargs grep $2 ;} #. 'str_to_find_in_files'
function findstrnam() { find $1 -iname '$2' | xargs grep '$3' ;} #. 'file_str' 'str_to_find' -sl # -sl to show filename only
function findstrnamtime() { find $1 -iname $2 -mtime $4 | xargs grep $3 ;} #. 'file_str' 'str_to_find' -1|1 #-1=today 1=olderthantoday

function dushdir() { for i in {`ls $1`};do du -sh $1/$i;done ;}
alias grepi='grep -i'
function grepr() { grep -r '$@' ;} # "string to find" "/dir/to/recurse"
function grephr() { grep -H -r '$@' ;} # same as above, only return filename string
function greprf() { grep -H $1 $2 -R | cut -d: -f1 ;} # "string" "/etc/*"


alias rk='rafkill' # < this is a game

alias relfh='readelf -h' #hello
alias relfS='readelf -S' #hello
alias relfs='readelf -s' #hello
alias relfl='readelf -l' #hello
#DANGEROUS
alias umntl='umount `mount | grep "/dev" | awk "{ print $1 }"`'
#-d=disassemble, -j=section
alias objdumpdj='objdump -d -j' #.text hello
alias oddj.text='objdump -d -j .text' #hello
alias oddj.data='objdump -d -j .data' #hello
#block started by symbol
alias oddj.bss='objdump -d -j .bss' #hello

#Virtual Memory Area--VMA for process
#first field is VMA addr range
#last field shows backing file
#before doing this you can do:
#gdb ->b main ->r ->q
function procsegn() { cat /proc/`pgrep $1`/maps ;} #process name
function procsegi() { cat /proc/$1/maps ;} #process id

alias gccc='gcc -c' #hello.c #creates hello.o
alias gcco='gcc -o' #hello hello.c
alias sp='splint' #hello.c
alias mkfat32='mkdosfs -F 32'
alias nasmfe='nasm -f elf' #hello.asm

function nasmfo() { nasm -f $1 $2 -o $3 ;} #bin hello.asm hello.com

alias ldso='ld -s -o' #hello hello.o

alias svnco='svn checkout' #URL path
alias svnrev='svn checkout -r' #rev URL path
alias svni='svn info' #path
alias svna='svn add' #path
alias svnrm='svn remove' #path
alias svnu='svn update'
alias svnup='svn update' #path
alias svnc='svn commit -m' #message
alias shfreq='cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies'
alias shgovr='cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors'
alias cpufs='cpufreq-selector -f' #1300000
alias rmlock="sudo rm /var/lib/dpkg/lock && sudo rm /var/cache/apt/archives/lock"
alias cronlu='sudo crontab -lu' #user
alias cronadd='sudo crontab -eu' #user
alias paros='/usr/lib/jvm/java-1.5.0-sun-1.5.0.15/jre/bin/java -jar /home/nopsidy/Desktop/paros/build/paros/paros.jar'

alias lastcrash='last |grep crash'
alias lastreboot='last reboot'
function lastn() { last '$@' ;}
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi

PATH=$HOME/bin:$PATH
PYTHONPATH=$HOME/lib/python
EDITOR=vim

export PATH PYTHONPATH EDITOR



Now we can use these alias' as bar codes. We can create bar codes with kbarcode. Then use them with a Symbol LS2208 barcode scanner or any scanner that understands Code 128 format, etc. You can change what the alias does for a scanned bar code. Instead of re-printing a new sheet of barcodes. I created 10 custom commands. You can set these to anything you like. I mostly use my alias to keep my commands in a central place. I helps me to keep things organized and easier to find. Instead of writing them down. Saves me time. I don't have to look through my notebook for the right commands.

Please share your .bashrc

You can get a symbol on ebay for $100-$150. This makes it very convenient to use for system maintenance. Especially if you know what commands you have to run ahead of time for a full system install. :) I've been working with python for a little while now. I would like to make a script to create barcodes for me automatically after I modify bashrc(nbrc&&sbrc)

You can download my current odt file. The password is lowercase "linux" without the quotes. I plan on adding prepend/append codes for a tab key or enter key to the cheat sheet. You can just store your .bashrc file on a usb stick. Plug it in with your trusty cheat sheet, a scanner and your on your way. I still don't know of a good way to transfer files via a keyspan. Is it possible? I think what I will do next is tape some cheat sheets on my walls next to my pc at home. Then I can sit relax and not type so much. :) I will keep updating this file.

Thank You.

2 comments:

Anonymous said...

you can upload files with kermit, zmodem, and a few other ways...

yay tacos!

Anonymous said...

Anonymous: Thanks. I will definitely check it out. I was actually looking for a way to upload files with a keyspan serial adaptor. A while back. Thanks.