Some Useful unix Command Which is Frequentlly used In Oracle-UNIX DBA
===================================================
To enable doskey mode in Unix
set -o vi
———————————————-
the “chgrp” command is used to change the group to a file:
root> chgrp <directory> group
———————————————-
The “awk” command it has its own scripting language:
For example, to display only the 6th field of the output from ‘who am i.’ (Field 6 is the IP address of your own
terminal session / PC.) you can use:
who am i | awk ‘{print $6}’
This can be used to automatically set the DISPLAY environment variable for users’ logins.
———————————————-
The “PS1″changes your prompt.
root> PS1=”Daid_DB1:> “
Daid_DB1:>
———————————————-
Enable FTP and TELNET Services
cd to /etc/xinetd.d
vi wu-ftpd
Change the disable field from “yes” to “no” and save changes.
vi telnet
Change the disable field from “yes” to “no” and save changes.
———————————————-
Information on Network
Display network interface configuration parameters
ifconfig -a
Address resolution display and control
arp -a
Check Routes:
netstat -rn
———————————————-
Cron Commands
Cron is a unix utility that allows tasks to be automatically run in the background at regular intervals by the cron
daemon often termed as cron jobs.
Crontab (CRON TABLE) is a file which contains the schedule of cron entries to be run and at specified times, you can
invoke it with the “crontab -e” command.
syntax
A crontab file has five fields for specifying day , date and time followed by the command to be run at that
interval. You can also specify a range of values.
* * * * * command to be executed
- – – – -
| | | | |
| | | | +—–> day of week (1 – 7) (monday = 1)
| | | +———–> month (1 – 12)
| | +—————–> day of month (1 – 31)
| +———————–> hour (0 – 23)
+—————————–> min (0 – 59)
The first 5 fields can be specified using the following rules:
* – All available values or “first-last”.
3-4 – A single range representing each possible from the start to the end of the range inclusive.
1,2,5,6 – A specific list of values.
1-3,5-8 – A specific list of ranges.
0-23/2 - Every other value in the specified range.
———————————————-
Useful Files
Here are some files that may be of use:
Path Contents
——– ————————–
/etc/passwd User settings
/etc/group Group settings for users.
/etc/hosts Hostname lookup information.
/etc/system Kernel parameters for Solaris.
/etc/sysconfigtab Kernel parameters for Tru64.
———————————————-
More Examples:
ls -al | pg do a full directory listing and prompt to stop stuff whizzing off the page.
ls | wc -l count the files in the current directory.
ls -alt list files in date order
ls -alt | head -10 as above but only display the first 10
ls -s | awk ‘{if ($1 > 50) print $1 ” ” $2 }’ list all files over 50 blocks in size.
ls -alq List files with hidden characters. Very useful when you cannot delete a file for an unknown reason, as
sometimes a file can be created with hidden control characters. (very common when stty not set properly)
ls -1 Shows the files in a list (just the file names, this option is useful in shell scripts where the files names
need to be fed into another program or command for manipulation)
ls -1h The option “-h” comes handy to display the size of the files in a human readable form.
ls -lr The parameter -r shows the output in the reverse order
ls -lR The -R operator makes the ls command execute recursively—that is, go under to the subdirectories and show
those files too
———————————————-
COMMAND EFFECT
:.= find out the current line number
:1 go to line 1
Ctrl-d page down
Ctrl-u page up
Shift-g go to end of file
i insert text at current position
Shift-a append text after end of current line
Shift-I insert text before start of current line
Esc get out of edit mode, back into normal vi command mode
dd delete current line
10dd delete 10 lines from current line on down
d shift-g delete all lines from current line and below
d 1 shift-g delete all lines from current line and above
. repeat previous command
shift-y yank (copy) current line
p paste that copy into line below
/data search forward for occurencies of string “data”
/ search forward for next occurrence of remembered search string
? search backward for next occurrence of remembered search string
:set ic make searches case insensitive
:1,$s/data/index/g replace all occurrencies of “data” with “index”
:1,$s/”//g remove all ” characters
:1,$s/$/ ;/ append ” ;” to the end of every line
:1,$s/^/rem / insert “rem ” to the start of every line
:w write (save) file
:q quit out of vi
:q! quit out of vi without saving changes
:wq write (save) file and quit out of vi
shift-z shift-z same as above “:wq” except does not write (change file modification times)
if you have not made any changes.
:n next file (when vi’ing a series of files, e.g. with using “vi *” at the command prompt)
u undo last command
shift-j Join next line onto end of current line
———————————————-