Thursday, September 10, 2009

Some important unix commands

1) Get the header of a url
curl -i url_value

2) Check if port is opened
netstat -an | grep port_value

3) tar/untar
tar -cvf ROOT.tar ROOT #create tar of ROOT
tar -xvf ROOT.tar #untar

jar xf kb.war #unwar war file

4) Copy to a remote host
scp unix_id_value@/path/to/
scp test.sh c0378015@iTest.corp.com:/tmp/

5)Search for a file in the Root as well as sub directories
find . -name "file_name" -print
find . -type d -maxdepth 2 -name "file_name*" -print

6) Check if a port is opened or not
telnet ip_address_of_host port
i.e. telnet 17.216.26.28 21 (21 is default port for ftp)
17.0.0.1 for localhost

7) Output of a url through unix commands:

curl -l 'http://canaanio.corp.com:11234/kb/index?page=iTestdebug&show=cookie'

8) Generate build file using ant commands:
//ant -buildfile path_of_build_file
ant -buildfile /Users/admin/Applications/workspace/iTest/build.xml

9) Read sth line from a file
sed -n sp REPORT
for 2nd line: sed -n 2p REPORT

10) Disk/File Usage
du -sk .
df -k .


11) list only file name
ls -1

12) Running processes
ps -ef | grep java


13) Kill/thread dump
kill -9 PID //for killing the process
kill -3 PID //for taking thread dump

14) Running script in background
nohup script.sh &

16) Know the current active shell : echo $SHELL #SHELL is environment variable
list supported shells: cat /etc/shells



15) Hiding password characters
echo "Enter your current password: \c"
stty -echo
read oldpass
stty echo