Thursday, August 07, 2008

Unix commands

#setup your env variables; look at these files
/etc/paths
~/.profile #if you have .bash_profile then this file does not get sourced
~/.bash_profile # many people source .profile from within .bash_profile
A best practice is to create several specific env scripts and source them from one of the two above.

# find all files from the current dir and down, that have words vijay kumar in them
grep -e "vijay kumar" -r .

#find all the files from current dir that have java in the filename and the string "vijay" in the content and print the line * filename
find ./ -name "*java" -exec grep -i vijay {} \; -print

# remove a folder and all its contents; f==force
rm -rf ./foo

#make copy of a directory along with structure, make default-abba is now duplicate of default
 cp -r default/ default-abba

#move the contents of one dir into the another dir;
mv /tmp/foo/   /myfiles/bar/

# find all files recursively that have case insensitive string vijay in the file content
grep -ri vijay *

#copy all files from server's /tmp/foobar folder to local
scp root@my.server.com:/tmp/foobar/* .
scp -r /tmp/myfolder . //for recursive copy and it does retain the folder structure in the target folder. it will create a folder named myfolder in the current dir.

#Using Macports from macports.org
sudo port install postgresql82 # will install the mac port of postgres client

#basic network troubleshooting when you can't connect to a remote system
sudo traceroute abc.com
curl http://www.abc.com:8080

# tail files
tail -n 200 -f filename
less filename

#find the pid of java and kill it
ps auxwww | grep java
kill -9 `pgrep java`
or
killall -9 java

#Screen tool to see what other user is typing
screen x
#then exit screen by ctrl AD

#login as su, your username must be in sudors table
sudo su -

#Run a command as another user
sudo -u username command

#add /sbin to your path in .bash_profile

#List only folders in a folder
ls -l | grep ^d

#List only files in a folder (don't included folders)
ls -l | grep ^- | awk '{print $9}'

#List files ordered by date, name, type etc.
ls -alt // sort by time, newest first
ls -altr // oldest files first

#List all filenames that have the word byline in the content of the file, add -r for recursive
grep -l byline * 

#Disk usages on file system, -h is for human readable
df -h

#get your wireless IP address
sudo /sbin/ifconfig getifaddr en1
#get your ethernet IP address
sudo /sbin/ipconfig getifaddr en0

# top and iotop
top
iotop
References: http://www.unix.com/unix-dummies-questions-answers/

# find the OS and architecture of your machine
uname -a
cat /etc/redhat-release //for CentOS only.

#see if your os is 32bit or 64 bit
uname -m

#find if you have a 64bit or 32 bit cpu
grep flags /proc/cpuinfo
and if you see "lm" in your output you have a 64bit machine, lm == long mode, see this

#see all active read and writes to your disk
$ fs_usage

# see all open files (reading/ writing)
$ lsof

#Killing a process belonging to another user named prep
sudo -u prep kill -9

#doing a for loop in a commandline shell script, this one copies from one svn folder to another
for f in *.xsd; do svn copy -m "Copying " "svn://dev-svn-1/user/mkennedy/$f" svn://dev-svn-1/app/java/ftp-support-service/metadata; done

#add a user to group 501
useradd -g 501 mkennedy

#find userid, group info of a user
id vijayk
id jboss

#iptables
vim /etc/resolv.conf
/etc/init.d/iptables stop
chkconfig iptables off
vim network-scripts/ifcfg-eth0
/etc/init.d/network restart

yum list installed httpd*

#hostname
hostname dev-mus-1

Sunday, August 03, 2008

Sortable column display in Grails

Grails provides a very convenient gsp tag to render a sortable table.

g:sortableColumn

I am looking to replace the Extreme Components plugin in the current Java app, and I think this will be a great replacement.