UNIX Tips - 1

This is the series of pages that consists of UNIX commands which regularly used by the Middleware Admins/  Developers /Architects. The major focus on high performance in your hands to reach success with  excellent tricks and templatising your work. We care about Solaris and Linux different commands that make more comfortable to play in your role.. 

1. How to edit multiple files at once?

Here is the simple way for this 

Learning the UNIX Operating System

Ans: Use the following commands at your command prompt :

cd dir for f in `ls *`; do sed "s/one/two/g" $f > tmp; mv tmp $f; done

Here I assumed the old str as 'one', new str as 'two' all those files are in the same directory. if the those files are in different directory then you need to use one more loop to traverse the directory tree.

2. How to get the port number associated with Process?

First you need to find whether the port is in use and established connection with other end points. Using netstat command you can find this port existing and running. 

$ netstat -na |grep <portno>

In Solaris Port number  associated with a process id is written into pfiles. By looking into the pfiles - meaning process file grep with port number. top most process indicated as initiator.

In Linux operating environment we can find the port associates with process with lsof command.

 

3. How to view Huge size of log files?

To view the Heavy size log files we cannot view them in normal vi editor.  Split the file as per the required criteria you are looking for. assume that myfile is of size 10000KB or above we make 500KB block of files as follows:

$ split -b 500k myfile segment

4. How to view the file without disturbing that file?

In Solaris we have 2 options:

vi -R "filename"

view "filename"

5. How to search and replace the test in the vi - editor?

:1,$s/oldstr/newstr/g

:%s/oldtext/newtext/g

6. How to goto starting of the line?

Esc 0(zero) takes you line starting point

7. How to goto End of the line in a vi editor?

Simple You need to press Esc and $ will takes you to the end of the line in the vi editor.

8. How search special characters in vi-editor?

Sol: situations like want to search a path which contains symbol(special character) / to search with this symbol we need to use stuffing charecter and the stuffing char is reverse slash \.

/\/export\/home

9. How to Search the multiple patterns in Solaris command line?

  egrep -e 'usage|else|if' startManagedWebLogic.sh

 

10. How to check RAM size in Solaris?

$ prtconf|grep Mem

Memory size: 32760 Megabytes

 

To Find the free Memory Size

sar -r 5 10

or

vmstat

11. How do you find the number of  Processors are there in SPARC machine?

$ psrinfo -p

4

12. How to know the number of Virtual processors on a SPARC machine?

$ psrinfo -pv

 

13. How to get non-zero size file list

 find logs -type f -size +0k | xargs ls

 

14. How to grep the CLASSPATH contents into line by line as per path-separator (:)?

Ans: The command could be the combination of grep and awk with a looping as follows:

grep CLASSPATH anylogfile.log|awk -F":" '{for (i=1 ; i<=NF ; i++) print $i}' 

15.  How to remove the duplicate lines from a text file?

To resolve this first you need to use 'sort'command, then file with -r option to get unique data. Redirect those lines with filter '>' which will create a new file with non duplicate lines.

16. How to find the processor type (32 bit or 64 bit) on a SPARC machine?

/usr/bin/isainfo -kv

16. How to check the java version supports 32 bit or 64 bit?

truss -t exec java -d64 -version

This will give you which JDK supported on your Solaris machine.

How to debug what is inside happenings at system, internal files while running starting a new service?

The strace is a wonderful tool for debug, this must be aware by every middleware architect/admin/developer. While installing WebLogic or any software this will help to find  what is happening internally, how the system calls happening. Where it is got stuck. A sample is as follows:

$ strace -fv -o output -p <WL PID> 

Good reference for ssh key-generation

http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html

The strace command discussion on stackoverflow