Thursday 28 July 2011

vi editor commands reference in UNIX

Esc   cancel/go back to normal mode
:q    quit
:wq!  write and quit
G     go to eof
1G    go to line 1
50G   go to line 50
-     go to begin of prev line
+     go to begin of next line
$     go to end of current line
^     go to begin of current line
/xxx  find xxx
z.    refresh
dd    delete line
D     delete rest of line
x     delete current char
a     insert after curremt char
i     insert ahead of current char
o     insert after current line
cw    change word under cursor
J     join lines
yy    copy line to clipboard
p     paste line above cursor

UNIX Commands Clearly





System status check

Listed here are a few system monitoring commands which should give you a rough idea of how the server is running.
# server information
uname -a

# server config information
prtconf
sysdef -i

# server up time
uptime

# disk free, listed in KB
df -kt

# mounted devices
mount

# network status
netstat -rn

# network configuration info
ifconfig -a

# processes currently running
ps -elf

# user processes
w
whodo
who am i
finger
ps

# virtual memory statistics
vmstat 5 5

# system activity reporter (Solaris/AIX)
sar 5 5

# report per processor statistics (Solaris)
mpstat 5 5
psrinfo

# swap disk status (Solaris)
swap -l

# shared memory
ipcs -b




Solaris note: SAR numbers can be misleading: as memory use by processes is freed, but not considered 'available' by the reporting tool. Solaris support has recommended using the SR (swap rate) column of vmstats to monitor the availability of memory. When this number reaches 150+, a kernel panic may ensue.


System startup

The kernel is loaded by the boot command, which is executed during startup in a machine-specific way. The kernel may exist on a local disk, CD-ROM, or network. After the kernel loads, the necessary file systems are mounted (located in /etc/vfstab), and /sbin/init is run, which brings the system up to the "initdefault" state set in /etc/inittab. Subsystems are started by scripts in the /etc/rc1.d,/etc/rc2.d, and /etc/rc3.d directories.


System shutdown


# shutdown the server in 60 seconds, restart system in administrative state
# (Solaris)
/usr/sbin/shutdown -y -g60 -i1  "System is begin restarted"

# shutdown the server immediately, cold state
# (Solaris)
/usr/sbin/shutdown -y -g0 -i0

# shutdown AIX server, reboot .. also Ctrl-Ctrl/Alt
shutdown -Fr



# restart the server
/usr/sbin/reboot


User accounts

Adding a unix account involves creating the login and home directory, assigning a group, adding a description, and setting the password. The .profile script should then be placed in the home directory.
# add jsmith account .. the -m parm forces the home dir creation
useradd -c "Jim Smith" -d /home/jsmith -m -s "/usr/bin/ksh" jsmith

# change group for jsmith
chgrp staff jsmith

# change jsmith password
passwd jsmith

# change jsmith description
usermod -c "J.Smith" jsmith

# remove ksmith account
userdel ksmith

# display user accounts
cat /etc/passwd

/* here is a sample .profile script, for sh or ksh */
stty istrip
stty erase ^H
PATH=/usr/bin:/usr/ucb:/etc:/usr/lib/scripts:/usr/sbin:.
export PATH
PS1='BOXNAME:$PWD>'
export PS1




Displaying files


# display file contents
cat myfile

# determine file type
file myfile

# display file, a screen at a time (Solaris)
pg myfile

# display first 100 lines of a file
head -100 myfile

# display last 50 lines of a file
tail -50 myfile

# display file that is changing, dynamically
tail errlog.out -f



File permissions

Permission flags: r = read, w = write, x = execute Permissions are displayed for owner, group, and others.
# display files, with permissions
ls -l
# make file readable, writeable, and executable for group/others
chmod 777 myfile

# make file readable and executable for group/others
chmod 755 myfile

# make file inaccessible for all but the owner
chmod 700 myfile

# make file readable and executable for group/others,
# user assumes owner's group during execution
chmod 4755 myfile

# change permission flags for directory contents
chmod -R mydir

# change group to staff for this file
chgrp staff myfile

# change owner to jsmith for this file
chown jsmith myfile



Listing files

See scripting examples for more elaborate file listings.
# list all files, with directory indicator, long format
ls -lpa

# list all files, sorted by date, ascending
ls -lpatr

# list all text files
ls *.txt



Moving/copying files

See scripting examples for moving and renaming collections of files.
# rename file to backup copy
mv myfile myfile.bak

# copy file to backup copy
cp myfile myfile.bak

# move file to tmp directory
mv myfile /tmp

# copy file from tmp dir to current directory
cp /tmp/myfile .



Deleting files

See scripting examples for group dissection routines.
# delete the file
rm myfile

# delete directory
rd mydir

# delete directory, and all files in it
rm -r mydir



Disk usage


# display disk free, in KB
df -kt

# display disk usage, in KB for directory
du -k mydir

# display directory disk usage, sort by largest first
du -ak / | sort -nr | pg



Using tar


# display contents of a file
tar tvf myfile.tar

# display contents of a diskette (Solaris)
volcheck
tar tvf /vol/dev/rdiskette0/unnamed_floppy

# copy files to a tar file
tar cvf myfile.tar *.sql

# format floppy, and copy files to it (Solaris)
fdformat -U -b floppy99
tar cvf /vol/dev/rdiskette0/floppy99 *.sql

# append files to a tar file
tar rvfn myfile.tar *.txt

# extract files from a tar filem to current dir
tar xvf myfile.tar



Starting a process

This section briefly describes how to start a process from the command line.
Glossary:

   & - run in background
   nohup (No Hang Up) - lets process continue, even if session is disconnected


# run a script, in the background
runbackup &

# run a script, allow it to continue after logging off
nohup runbackup &


# Here nohup.out will still be created, but any output will
# show up in test70.log.  Errors will appear in nohup.out.

nohup /export/spare/hmc/scripts/test70 > test70.log &



# Here nohup.out will not be created; any output will
# show up in test70.log.  Errors will appear test70.log also !

nohup /export/spare/hmc/scripts/test70 > test70.log 2>&1  &








Killing a process


1) In your own session;  e.g. jobs were submitted, but you never logged out:

ps                           # list jobs
kill -9  < process id>       # kill it



2) In a separate session

# process ID appears as column 4
ps -elf | grep -i 

kill -9  < process id>       # kill it



3)  For device (or file)

# find out who is logged in from where

w

# select device, and add /dev ... then use the fuser command

fuser -k /dev/pts/3





Redirecting output

Output can be directed to another program or to a file.
# send output to a file
runbackup > /tmp/backup.log

# also redirect error output
runbackup > /tmp/backup.log 2> /tmp/errors.log

# send output to grep program
runbackup | grep "serious"



Date stamping, and other errata

Other errata is included in this section
# Date stamping files
# format is :
# touch -t yyyymmddhhmi.ss filename

touch -t 199810311530.00 hallowfile

# lowercase functions (ksh)
typeset -u newfile=$filename

# date formatting, yields 112098 for example
date '+%m%d%y'

# display a calendar (Solaris / AIX)
cal

# route output to both test.txt and std output
./runbackup | tee test.txt

# sleep for 5 seconds
sleep 5

# send a message to all users
wall "lunch is ready"

# edit file, which displays at login time (message of the day)
vi /etc/motd

# edit file, which displays before login time (Solaris)
vi /etc/issue


UNIX Tips


The following commands can be used in the vi text editor while in Command Mode.
To switch from Insert Mode to Command Mode, press the Escape (Esc) key.

Cursor Movement

Command Function
h One space to the left
j One space to up
k One space down
l One space to the right
<Return> Beginning of new line
- Beginning of previous line
^ Beginning of current line
$ End of current line
<Space> Forward one space
nG Beginning of line n
b Beginning of current word
w Beginning of next word
e End of current word
Control - e Scroll forward
Control - b Scroll backward
/pattern First occurence of pattern
n Next occurence of pattern
N Previous occurence of pattern
/ Repeats last pattern search

Text Insertion and Deletion

Command Function
A Appends text at the end of the line
i Inserts text to the left of the cursor
I Inserts text at the beginning of the line
o Opens a new line below the current line for text to be inserted
O Opens a new line above the current line for text to be inserted
x Deletes character at cursor position
X Deletes character left of cursor position
dd Deletes current line
dw Deletes current word
d) Deletes rest of sentence
D or d$ Deletes from cursor to end of line
P Puts back text from the previous delete
rx Replaces selected character with x
u Undoes last change
U Restores current line
:R myfile Appends file "myfile" to current file at current cursor position
Delete Overwrites last character during text insertion
Escape Stops text insertion, returns to command mode

Change Commands

Command Function
cw Changes characters of current word until escape key is pressed
c$ Changes text up to the end of the line
C or cc Changes remaining text on the current line until escape key is pressed
~ Changes case of the current character
xp Transposes the current and following characters
J Joins current line with the next line
s Deletes current character and enters insertion mode
rx Replaces current character with x
R Replaces the following characters until escape key is pressed
yy Puts current line in a buffer without deleting the line
p Places the line stored in buffer after the current position of the cursor

Screen Commands

Command Function
h One space to the left
j One space to up
k One space down
l One space to the right
<Return> Beginning of new line
- Beginning of previous line
^ Beginning of current line
$ End of current line
<Space> Forward one space
nG Beginning of line n
b Beginning of current word
w Beginning of next word
e End of current word
Control - e Scroll forward
Control - b Scroll backward
/pattern First occurence of pattern
n Next occurence of pattern
N Previous occurence of pattern
/ Repeats last pattern search

Other Tips

Command Function
"vi myfile" Creates or opens a file in vi, where "myfile" is the name of the file
(type this command at the standard Unix prompt to open the vi text editor)
ZZ Saves changes to the current file and exits vi
:wq Writes changes to the current file and quits the editing session
:q! Quits the editing session without saving changes

Weblogic and different version Oracle JDBC driver Problem

When trying to configure a new JDBC Datasource in Weblogic the following error was shown in the console: java.lang.ArrayIndexOutOfBoundsException: 7

The Weblogic server log shows the following trace:
01####       <> <>    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:989)
02    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:292)
03    at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:508)
04    at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:203)
05    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
06    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
07    at com.bea.console.utils.jdbc.JDBCUtils.testConnection(JDBCUtils.java:505)
08    at com.bea.console.actions.jdbc.datasources.createjdbcdatasource.CreateJDBCDataSource.testConnectionConfiguration(CreateJDBCDataSource.java:458)
09    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
11    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
12    at java.lang.reflect.Method.invoke(Method.java:597)
13    ....
After some debugging the source of the problem was an old Oracle Database version (8.1.7) used in the test environment. Apparantly the combination with Weblogic 10.3.3 & Oracle JDBC driver (ojdbc6.jar) is not supported/allowed/working. This old database version was not used in the new Acceptance and Production environment so we needed a simple work-around.
We decided to try and use an old version of the ojdbc driver (1.4) instead of the default version (6).
So in our setDomainEnv.cmd we defined: set PRE_CLASSPATH=/oracle/library/ojdbc14.jar
As we had a dedicated Weblogic Test Domain we could configure it like this for the whole domain.
After restarting the Managed Server we could see in the logging that the driver has been loaded first:
java.class.path = /oracle/library/ojdbc14.jar;/oracle/ofmw11113/patch_wls1033/…………
And after restart configuring the JDBC Datasource succeeded.


Remarks:
  • Remember that this solution above impacts all Oracle JDBC datasources on the Managed Server
  • Oracle does not(!) support the use of ojdbc14.jar in an environment with Java version 6 or later.
  • However ojdbc14 should work just fine, certainly for us as a work-around. The primary differences between 1.4 and newer versions as 6 is that newer versions support new features of the JDBC API and Oracle Database.

Wednesday 27 July 2011

What is a Machine in Oracle Weblogic Server?

A Machine in a Oracle Weblogic server is a computer that hosts the Oracle Weblogic Server instances.  Runs a supported operating system platform and it is used by Node Manager to restart a failed Managed servers.

Weblogic server status check - UNIX command

To automate weblogic managed server startup steps, need to check Admin server status first. Then start managed server. Check managed server status before continuing next steps like bringing up services deployed. Found to be useful to use weblogic.Admin option to achieve this easily,

Here is the step to check Admin server status

. setEnv.sh
$JAVA_HOME/bin/java weblogic.Admin -url $admin_server PING 1 >/dev/null 2>&1
admin_server_status=$?

Step to check Managed server status

ms_server_status=`$JAVA_HOME/bin/java weblogic.Admin -url $admin_server GETSTATE $app_name grep -c RUNNING `

How to find which port listing for process id?

in windows:

use this command netstat -o
it will list out process id, port number, listen address, port status, process name

for unix, use lsof

UNIX Command Reference

cd d              Change to directory d
mkdir d           Create new directory d
rmdir d           Remove directory d
mv f1 [f2...] d   Move file f to directory d
mv d1 d2          Rename directory D1 as D2
passwd            Change password
alias name1 name2 Create command alias
unalias name1     Remove command alias name1
rlogin nd         Login to remote node
logout            End terminal session
                                                  
                                                  
ls [d] [f...]     List files in directory
ls 1 [f...]      List files in detail
alias [name]      Display command aliases
printenv [name]   Print environment values
quota             Display disk quota
date              Print date & time
who               List logged in users
whoami            Display current user
finger [username] Output user information
chfn              Change finger information
pwd               Print working directory
history           Display recent commands
! n               Submit recent command n
                                                  
                                                  
Ctrl/c *          Interrupt processes
Ctrl/s *          Stop screen scrolling
Ctrl/q *          Resume screen output
sleep n           Sleep for n seconds
jobs              Print list of jobs
kill [%n]         Kill job n
ps                Print process status stats
kill 9 n         Remove process n
Ctrl/z *          Suspend current process
stop %n           Suspend background job n
command&          Run command in background
bg [%n]           Resume background job n
fg [%n]           Resume foreground job n
exit              Exit from shell

Important UNIX Commands

Advance Unix Management
________________________________________

xyx:/>compress
-command compresses a file and returns the original file with .z extension, to uncompress this filename’s file use uncompress filename command.

Available Options
-bn limit the number of bits in coding to n
-c write to standard output
-f compress conditionally, do not prompt before overwriting files
-v Print the resulting percentage of reduction for files
________________________________________

xyx:/>uncompress
- command file uncompresses a file and return it to its original form.
uncompress filename.Z this uncompressed the compressed file to its original name.
-c write to standard output without changing files
________________________________________

xyx:/>cpio

- command is useful to backup the file systems. It copy file archives in from or out to tape or disk, or to another location on the local machine.

cpio flags [options]
It has three flags, -i, -o, -p
cpio -i [options] [patterns]
-> cpio -i copy in files who names match selected patterns
-> If no pattern is used all files are copied in
-> It is used to write to a tape
cpio -o
-> Copy out a list of files whose name are given on standard output
cpio -p
-> Copy files to another directory on the same system.
Options
-a reset access times of input files
-A append files to an archive (must use with -o)
-b swap bytes and half-words. Words are 4 bytes
-B block input or output using 5120 bytes per record
-c Read or write header information as Ascii character
-d create directories as needed
-l link files instead of copying
-o file direct output to a file
-r rename files interactively
-R ID reassign file ownership and group information to the user's login ID
-V print a dot for each file read or written
-s swap bytes
-S swap half bytes
-v print a list of filenames

Imp Examples
-> find . -name "*.old" -print | cpio -ocvB > /dev/rst8 will backup all *.old files to a tape in /dev/rst8
-> cpio -icdv "save"" < /dev/rst8 will restore all files whose name contain "save" -> find . -depth -print | cpio -padm /mydir will move a directory tree.
________________________________________

xyx:/>dump
- command is useful to backup the file systems, copies all the files in file system that have been changed after a certain date. This command is good for incremental backups on HP Unix
date is derived from /var/adm/dump dates and /etc/fstab.

/usr/sbin/dump [option [argument ...] file system]
Options where
where 0-9 dump level. 0 option causes entire file system to be dumped or copied
b blocking factor taken into argument
d density of tape, default value is 1600
f place the dump on next argument file instead of tape
________________________________________

xyx:/>pack
- command compacts each file and combine them together into a filename.z file. The original file is replaced. pcat and unpack will restore packed files to their original form.

Available Options
-p Print number of times each byte is used
-f Force the pack even when disk space isn't saved
To display Packed files in a file use pcat command
-> pcat filename.z
To unpack a packed file use unpack command as unpack filename.z
________________________________________

xyx:/>tar
- command creates an archive of files into a single file. tar copies and restore files to a tape or any storage media.

Examples:
xyx:/>tar cvf /dev/rmt/0 /bin /usr/bin creates an archive of /bin and /usr/bin, and store on the tape in /dev/rmt0.
xyx:/>tar tvf /dev/rmt0 will list the tape's content in a /dev/rmt0 drive.
xyx:/>tar cvf - 'find . -print' > backup.tar will creates an archive of current directory and store it in file backup.tar.

Functions and options:
c creates a new tape
r append files to a tape
t print the names of files if they are stored on the tape
x extract files from tap
b n use blocking factor of n
l print error messages about links not found
L is symbolic links
v print function letter (x for extraction or a for archive) and name of files.
________________________________________


xyx:/>mt - command is used for tape and other device functions like rewinding, ejecting, etc. It give commands to tape device rather than tape itself. mt command is BSD command and is seldom found in system V unix versions.
syntax is
mt [-t tapename] command [count]
mt for HP-UX accept following commands.

Important Examples to use
mt -t /dev/rmt/0mnb rew will rewind the tape in this device
mt -t /dev/rmt/0mnb offl will eject the tape in this device

________________________________________

xyx:/>calendar
- command reads your calendar file and displays only lines with current day.

Examples:-
12/20 Test new software.
1/15 Test newly developed 3270 product.
1/20 Install memory on HP 9000 machine.
On dec 20th the first line will be displayed. you can use this command with your crontab file or in your login files.
________________________________________

xyx:/>nohup
- command, is used with prefix of any command, which continue running the command even if you shut down your terminal or close your login session.

xyz:/>nohup top

________________________________________

xyx:/>tty
- command is used to display terminal information.
-l will print the synchronous line number
-s will return only the codes: 0 (a terminal), 1 (not a terminal), 2 (invalid options) (good for scripts)
________________________________________

Handy for Unix Shell Programming
________________________________________

Shell programming concepts and commands:
Shell programming is an integral part of Unix operating system. It is command line user interface to Unix system, User have an option of picking an interface on Unix such as ksh, csh, or default sh, these are called shells. Shell programming is used to automate many tasks. ________________________________________

Bourne Shell (sh shell):-
sh or Bourne shell is default shell of Unix operating systems and is the simplest shell in Unix systems.

Ksh shell (Korn):-
Ksh or Korn shell is widely used shell.

csh or c shell:-
csh is second most used shell.

echo command

The echo utility writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. If there are no arguments, only the NEWLINE character will be written.
echo is useful for producing diagnostics in command files, for sending known data into a pipe, and for displaying the contents of environment variables.

line command
The line utility copies one line (up to and including a new-line) from the standard input and writes it on the standard output. It returns an exit status of 1 on EOF and always prints at least a new-line. It is often used wwithin shell files to read from the user's terminal.

sleep command
The sleep utility will suspend execution for at least the integral number of seconds specified by the time operand.
Example 1: Suspending command execution for a time
To execute a command after a certain amount of time:
example% (sleep 105; command)&
Example 2: Executing a command every so often
example% while true
do
command
sleep 37
done

test command
The test utility evaluates the condition and indicates the result of the evaluation by its exit status. An exit status of zero indicates that the condition evaluated as true and an exit status of 1 indicates that the condition evaluated as false.

cc compiler (c programming language compiler).
Since Unix is itself is written in C programming language, most Unix operating systems come with c compiler called cc.

File Transfer and Communication Management

________________________________________

xyx:/>cu
command, is used for communications over a modem or direct line with another Unix system.
________________________________________

xyx:/>ftp
command is used to execute for files transfer over two systems.

-d enable debugging.
-g disable filename globing.
-i turn off interactive prompts.
-v verbose on. Show all responses from remote server.
________________________________________

xyx:/>login
command invokes a login session to a Unix box, System prompts you to enter userid and password.

xyx:/>rlogin command is used to log on to remote Unix systems, user must have permissions on both systems as well as same user id, or an id defined in .rhosts file.
xyx:/>rlogin host
________________________________________

xyx:/>talk
command used to invoke talk program available on all unix system which lets two users exchange information back and forth in real time.

xyx:/>talk userid@hostname
________________________________________

xyx:/>telnet
- command invokes a telnet protocol which lets you log on to different unix, vms or any machine connected over TCP/IP protocol, IPx protocol or otherwise.

xyx:/>telnet host1
xyx:/> telnet
telnet>
________________________________________

xyx:/>vacation
command is used for out of office message to be send. It returns a mail message to sender announcing that you are on vacation.
/export/home/crk> vacation
This program can be used to answer your mail automatically
when you go away on vacation.
You need to create a message file in /export/home/crk/.vacation.msg first.
Please use your editor (vi) to edit this file.
"/export/home/crk/.vacation.msg" 4 lines, 130 characters
Subject: away from my mail
I will not be reading my mail for a while.
Your mail regarding "$SUBJECT" is read when I return.
N.B:- To disable this feature, use mail -F " "
-d will append the date to the log file.
-F user will forward mail to user when unable to send mail to mail file.
-l log file will record in the log file the names of senders who received automatic reply.
-m mail file will save received messages in mail file.
________________________________________

xyx:/>write
command initiate an interactive conversation with user.

xyx:/>write user1 tty
________________________________________
System reporting and Status Management
________________________________________

xyx:/>at command.
at command is also used like crontab command, to schedule jobs.

-f file execute commands in a file.
-m sends mail to user after job is completed.
-l list all jobs that are scheduled and their jobnumbers.
-r job number will remove specified jobs that were previously scheduled.
________________________________________

xyx:/>chmod
Command is used to change permissions on a file.
xyx:/>ls -la test.txt
-rw-rw-rw- 1 qtr pmpcr 135 OCT 20 16:14 test.txt
-rw-rw-rw- meaning that owner can read and write file, member of the owner's group can read and write this file and anyone else connected to this system can read and write this file., next qtr is owner of this file pmpcr is the group of this file, there are 135 bytes in this file, this file was created on Oct 20 at time16:14 and at the end there is name of this file.
xyx:/>chmod 600 file1
________________________________________

xyx:/>chgrp command is used to change the group of a file or directory.
xyx:/>chgrp [options] newgroup files
Newgroup is either a group Id or a group name located in /etc/group .
Available Options:
-h will change the group on symbolic links.
-R recursively descend through directory changing group of all files and subdirectories.
________________________________________

xyx:/>chown command.
chown command to change ownership of a file or directory to one or more users.

xyx:/>chown
options new owner files
Available important Options
-h will change the owner on symbolic links.
-R will recursively descend through the directory, including subdirectories and symbolic links.
________________________________________

xyx:/>crontab is used to schedule jobs. Permission to run this command should have been granted.
Normally Jobs are scheduled in five numbers, as follows.
Minutes 0-59
Hour 0-23
Day of month 1-31
month 1-12
Day of week 0-6 (0 is sunday)
Example
To schedule a job which runs from script named backup_jobs in /usr/local/bin directory on sunday (day 0) at 11.25 (22:25) on 15th of month.

* represents all values.
25 22 15 * 0 /usr/local/bin/backup_ xyx:/>jobs
The * here tells system to run this each month.
Syntax is
xyx:/>crontab file ## To create a file with the scheduled jobs like above
xyx:/>crontab file1 #
to schedule job
________________________________________

xyx:/>date - command displays to days date, to use it type date at command prompt
xyx:/>date
Fri Oct 20 16:10:58 EDT 2010

________________________________________

xyx:/>df
df command displays information about mounted filesystems.
xyx:/>df

/ (/dev/md/dsk/d0 ): 3838540 blocks 431434 files
/proc (/proc ): 0 blocks 29848 files
/etc/mnttab (mnttab ): 0 blocks 0 files
/dev/fd (fd ): 0 blocks 0 files
/var (/dev/md/dsk/d20 ): 2559692 blocks 587286 files
/var/run (swap ):31292080 blocks 789270 files
/dev/vx/dmp (dmpfs ):31292080 blocks 789270 files
/dev/vx/rdmp (dmpfs ):31292080 blocks 789270 files
/tmp (swap ):31292080 blocks 789270 files
/opt (/dev/md/dsk/d30 ): 2509926 blocks 609248 files
/opt/crk (/dev/md/dsk/d40 ):32416940 blocks 2240301 files

Available Options
-b show only the number of free blocks.
-e show only the number of free files.
-k list allocation in kilobytes.
-l show only on local file systems.
-n list only the file system name type
________________________________________

xyx:/>du
du command displays disk usage.
________________________________________

xyx:/>env

env command displays all the variables set in your profile
________________________________________

xyx:/>finger - command used to display information about local and remote users.
xyx:/>finger user1@abc
________________________________________

xyx:/>ps
ps command is the most use
ful command for systems administrators. It reports information on active processes.
Available options.
-a Lists all processes in system except processes not attached to terminals.
-e Lists all processes in system.
-f Lists a full listing.
-j print process group ID and session ID.

xyx:/>ps -eafj |more
UID PID PPID PGID SID C STIME TTY TIME CMD
root 0 0 0 0 0 Sep 08 ? 0:19 sched
root 1 0 0 0 0 Sep 08 ? 2:51 /etc/init -r
root 2 0 0 0 0 Sep 08 ? 0:00 pageout
root 3 0 0 0 1 Sep 08 ? 634:05 fsflush
root 6817 1 6817 6817 0 Sep 08 ? 0:00 /usr/lib/saf/sac -t 3
00
root 590 1 590 590 0 Sep 08 ? 0:06 /usr/lib/inet/xntpd
root 689 1 0 0 0 Sep 08 ? 0:00 /sbin/sh - /usr/lib/v
xvm/bin/vxconfigbackupd
root 20 1 20 20 0 Sep 08 ? 3:48 vxconfigd -x syslog -
m boot
________________________________________

xyx:/>ruptime - command tells the status of local networked machines.

Available options.
-a include user even if they've been idle for more than one hour
-l sort by load average
-r reverse the sort order
-t sort by uptime
-i sort by number of users
________________________________________

xyx:/>shutdown command executed by root. To gracefully bring down a system, shutdown command is used.
-gn use a grace-period of n seconds (default is 60).
-ik tell the init command to place system in a state k.
s single-user state (default)
shutdown for power-off
1 like s, but mount multi-user file systems
5 stop system, go to firmware mode
6 stop system then reboot
-y suppress the default prompt for confirmation.
________________________________________

xyx:/>stty - command sets terminal input output options for the current terminal.
Without options stty reports terminal settings.

-a report all options.
-g report current settings.
Available Modes
0 hang up phone.
n set terminal baud.
erase keyname, will change your keyname to be backspace key.
________________________________________

xyx:/>who - command displays information about the current status of system.
who options file
Who as default prints login names of users currently logged in.
Available Options
-a use all options.
-b Report information about last reboot.
-d report expired processes.
-H print headings.
-p report previously spawned processes.
-u report terminal usage.
________________________________________
File Redirection Management
________________________________________
xyx:/>cal > cal.txt , create a new file called cal.txt that has calendar for current month.
> sign redirects output from stdout (screen) to a file. If file already exists, it will over right the content with latest information being redirected
>> will append the file if it is already existing
Comparison and Search Management
________________________________________

xyx:/>diff command. Compares the two files and print out the differences between them


Let two ascii text files file1 and file2
Contents of file1:
This is a test file to compare the file contents
This is a test file to compare the file contents
This is a test file to compare the file contents
This is a test file to compare the file contents

Contents of file2 contains
This is a second test file to compare the file contents
This is a test file to compare the file contents
This is a test file to compare the file contents
This is a test file to compare the file contents
xyx:/>diff file1 file2
0a1
> This is a second test file to compare the file contents
3d3
This is a test file to compare the file contents
________________________________________

xyx:/>cmp command. Compares the two files, similarly as diff.

xyx:/>cmp file1 file2
file1 file2 differ: char 12, line 1
________________________________________

xyx:/>dircmp Command compares two directories. Let us say dir1 and dir2 and each has 5-10 files in it.
Then
xyx:/> dircmp dir1 dir2
Nov 20 14:14 2010 dir1 only and dir2 only Page 1
./userfile/duplicate_Tue.lo ./add_test_profiles.sh
./ userfile/duplicate2 _Tue_09 ./afiedt.buf
./ userfile/duplicate3 _Fri.log ./alter_user_profiles.sh
./ userfile/duplicate4 _Fri_113 ./kb.sh

________________________________________

xyx:/>grep Command is the most useful search command. Mostly used with combination with other commands like PS command, to find processes running on system, a pattern in a file, search one or more files to match an expression etc.

xyx:/> ps -ef | grep sleep will display all the sleep processes running in the system as follows.

root 15258 4190 0 14:21:25 ? 0:00 sleep 300
root 15890 15879 0 14:24:59 ? 0:00 sleep 360
_______________________________________

xyx:/>find command very useful for search of any file anywhere , provided that file and directory you are searching has read write permission set to you ,your group or all.
Some common Examples:

xyx:/>find $crk -print will lists all files in crk home directory.

xyx:/>find /crkdir -name client1 -print will list all files named client1 in /crkDir directory.
xyx:/>find / -type d -name 'man*' -print will list all manpage directories.
xyx:/>find / -size 0 -ok rm {} \; will remove all empty files on system.


_______________________________________

Text processing tools
________________________________________

xyx:/>cut command selects a list of columns or fields from one or more files and show on screen

-c is for character from first columns and -f for fields.

Example:
xyx:/>cut -c1,4 file1
ts
ts
ts
It is printing character of columns 1 and 4 of this file which contains t and s (part of this).

-c list cut the column positions identified in list.

-f list cut the fields identified in list.
-s used with -f to suppress lines without delimiters.

________________________________________

xyx:/>paste command merge the lines of one or more files into vertical columns separated by a tab.

xyx:/>paste file1 file2
This is a test file to compare the file contents This is a second test file to compare the file contents
This is a test file to compare the file contents This is a test file to compare the file contents
This is a test file to compare the file contents This is a test file to compare the file contents
This is a test file to compare the file contents This is a test file to compare the file contents
Let us take file1
this is firstline
and a file named testfile2 contains
this is testfile2
then running this command
paste testfile testfile2 > outputfile ##will put this into outputfile
this is firstline this is testfile2
it contains contents of both files in columns.
who | paste - - will list users in two columns.

Available imp Options:
-d'char' separate columns with char instead of a tab.
-s merge subsequent lines from one file.
________________________________________

xyx:/>sort command.
sort command sort the lines of a file or files, in alphabetical order. for example if you have a file named testfile with these contents

zzz
aaa
1234
yuer
wer
qww
wwe
Then running
> sort testfile
will give us output of

1234
aaa
qww
wer
wwe
yuer
zzz
Available Options:
-b ignores leading spaces and tabs.
-c checks whether files are already sorted.
-d ignores punctuation.
-i ignores non-printing characters.
-n sorts in arithmetic order.
-o file put output in a file.
+m[-m] skips n fields before sorting, and sort upto field position m.
-r reverse the order of sort.
-u identical lines in input file apear only one time in output.
________________________________________

xyx:/>uniq command.
uniq command removes duplicate adjacent lines from sorted file while sending one copy of each second file.
Examples


sort names | uniq -d will show which lines appear more than once in names file.
Available Options:
-c print each line once,
-d print duplicate lines once, but no unique lines.
-u print only unique lines.
________________________________________
xyx:/>awk and nwak command.
awk is more like a scripting language builtin on all unix systems. Although mostly used for text processing, etc.


Examples: to show total space in your system

xyz:/>df -t | awk 'BEGIN {tot=0} $2 == "total" {tot=tot+$1} END {print (tot*512)/1000000}'

Here the output of command df -t is being passed into awk which is counting the field 1 after pattern "total" appears. Same way if you change $1 to $4 it will accumulate and display the addition of field 4 which is used space.
________________________________________

xyx:/>sed command. sed command launches a stream line editor which are used at command line.
you can enter your sed commands in a file and then using -f option edit your text file. It works as
sed [options] files
Available options:
-e 'instruction' editing instruction to the files.
-f script set of instructions from the editing script.
-n suppress default output.
_______________________________________

xyx:/>vi editor.

vi command launches a visual editor. vi editor is a default editor of all Unix systems. It has several modes. In order to write characters you will need to hit i to be in insert mode and then start typing. Make sure that your terminal has correct settings, vt100 emulation works good if you are logged in using pc.
Once you are done typing then to be in command mode where you can write/search/ you need to hit
Examples:-
Case I. To edit a file type
vi filename
:w filename to write
Case II. In case you are done writing and want to exit
:w! will write and exit.
Available options:
i for insert mode.

I inserts text at the cursor
A appends text at the end of the line.
a appends text after cursor.
O open a new line of text above the cursor.
o open a new line of text below the cursor.

: for command mode
to invoke command mode from insert mode.
:!sh to run unix commands.
x to delete a single character.
dd to delete an entire line
ndd to delete n number of lines.
d$ to delete from cursor to end of line.
yy to copy a line to buffer.
P to paste text from buffer.
nyy copy n number of lines.
:%s/string A/string B /g to replace string A with string B in whole file.
G to go to last line in file.
1G to go to the first line in file.
w to move forward to next word.
b to move backwards to next word.
$ to move to the end of line.
J join a line with the one below it.

/string to search string in file.
n to search for next occurrence of string.

UNIX commands to Explore
xyx:/>pwd command. Show home directory on screen, PWD means print working directory.
/export/home/crk
is output for the command when used pwd in /export/home/crk directory.
________________________________________

xyx:/>mkdir command.
xyx:/>mkdir crk will create new directory, i.e. here crk directory is created.

________________________________________

xyx:/>cd command.
cd crk will change directory from current directory to crk directory.

________________________________________

xyx:/>cat command
cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).

________________________________________

xyx:/>head command.
head filename by default will display the first 10 lines of a file. For first 50 lines you can use head -50 filename.

xyz:/> head -50 file1
________________________________________

xyx:/>tail command.
tail filename by default will display the last 10 lines of a file. For last 50 lines then you can use tail -50 filename.

________________________________________

xyx:/>more command. more command will display a page at a time and then wait for input which is spacebar.
For example if you have a file which is 500 lines and you want to read it all. So you can use
more filename
________________________________________

xyx:/>wc command
wc command counts the characters, words or lines in a file depending upon the option.

Available Options
wc -l filename will print total number of lines in a file.
wc -w filename will print total number of words in a file.
wc -c filename will print total number of characters in a file.
________________________________________

xyx:/>man command. This is help command for looking any information about that command available,
man cp show cp command details with example and how you can use it.
man -k pattern command gives search for particular pattern with details.

________________________________________

xyx:/>banner command. For printing poster type ascii character, useful for making identifiable logins, any presentable output. Like below

xyx:/> banner crk


#### ##### # #
# # # # # #
# # # ####
# ##### # #
# # # # # #
#### # # # #

________________________________________

xyx:/>cal command. shows the calander on current month by default.
Witout options with cal command , will show current month calander, refer below example for more clarification


xyz:/>cal

November 2010
S M Tu W Th F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

N.B: if want to print calendar of 2nd Month of 2008
xyz> cal 2 2008
February 2008
S M Tu W Th F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29
________________________________________

xyx:/>ls command
ls command is most widely used command and it displays the contents of directory.

options
ls list all the files in your home directory.
ls -l list all the file names, permissions, group, in long format.
ls -a list all the files including hidden files that start with .
ls -lt list all files names based on the time of creation, newer first.
ls –Fx list files and directory names will be followed by slash.
ls -R lists all the files and files in the all the directories, recursively.
ls -R | more will list all the files and files in all the directories, one page at a time.
________________________________________

xyx:/>file Command displays about the contents of a given file, whether it is a text (Ascii) or binary file. To use it type
file filename. For example I have cal.txt which has ascii characters about calander of current month and I have resume1.doc file which is a binary file in MS word. Result would be as

file resume.doc

resume1.doc: data
file cal.txt
cal.txt: ascii text

________________________________________

xyx:/>cp command.
cp command copies a file. If I want to copy a file named oldfile in a current directory to a file named newfile in a current directory.


xyz:/>cp oldfile newfile

To copy oldfile to other directory in /tmp

xyz:/>cp oldfile /tmp/newfile.
Available Options are :
cp are -p and -r . -p options preserves the modification time and permissions,
-r recursively copy a directory and its files, duplicating the tree structure.
________________________________________

xyx:/>rcp command.
rcp command will copy files between two unix systems and works just like cp command (-p and -i options too).

Let us assume a unix system that is called unix1 and want to copy a file which is in current directory to a system that is called unix2 in /usr/om/ directory then you can use rcp command
rcp filename unix2:/usr/om
You will also need permissions between the two machines. For more infor type man rcp at command line.
________________________________________

xyx:/>mv command.
mv command is used to move a file from one directory to another directory or to rename a file.

Some examples:
mv oldfile newfile will rename oldfile to newfile.
mv -i oldfile newfile for confirmation prompt.
mv -f oldfile newfile will force the rename even if target file exists.
mv * /usr/om/ will move all the files in current directory to /usr/om directory.
________________________________________

xyx:/>ln command.
Instead of copying you can also make links to existing files using ln command.
If you want to create a link to a file called myfile in /usr/local/bin directory then you can enter this command.

ln myfile /usr/local/bin/myfile
Some examples:
ln -s fileone filetwo will create a symbolic link and can exist across machines.
ln -n option will not overwrite existing files.
ln -f will force the link to occur.
________________________________________

xyx:/>rm command.
To delete files use rm command.

Available Options:
rm oldfile will delete file named oldfile.
rm -f option will remove write-protected files without prompting.
rm -r option will delete the entire directory as well as all the subdirectories, very dangerous command.
________________________________________

xyx:/>rmdir command. Remove directory or directories if a directory is empty.

• rmdir om --> to remove om directory.
• rmdir -p --> to remove directories and any parent directories that are empty.