 |
|
Oracle UNIX
Administration Editing and Viewing Files
Oracle UNIX/Linux Tips by Burleson Consulting |
Viewing and editing files in UNIX
UNIX provides several commands and utility
programs for viewing the contents of data files. These tools
are often very foreign and cryptic to the UNIX beginner, but it is
critical to the effective management of Oracle that you become
comfortable with these powerful tools:
* The vi editor ? pronounced ?vee-eye? ?
This is a powerful text-processing program, which, once mastered, is
far faster than any text editor known to personal computers.
Inside the vi editor, every key (both uppercase and lowercase)
performs an editing function. For vi for read-only access,
files can be accessed using the view command.
* The cat command - The cat (concatenate)
command, (like the MS-DOS type command), displays the contents of a
file on the screen. For example, entering the command cat food would
display the entire food file on your screen.
* The more command ? The more command is
used to display a file, one screen at a time. For example,
entering the command more food would list the food file, and you
press the spacebar for the next screen of text.
* The head command ? The head command is
used to display the first lines of a file. For example,
entering the command head start would display the first three lines
of the start file.
* The tail command ? The tail command is
used to display the last lines in a file. For example, entering the
command tail gating would display the last three lines of the gating
file.
Let?s take a quick look at some of these
commands
The UNIX cat command
In addition to displaying the contents of
UNIX files, the cat command can be used to join file together.
For example, the following command will join together three Oracle
trace files and mail then to the DBA:
cat
test_ora_1 test_ora_2 test_ora_3 > \
mail ?s ?Daily trace files? don@mydomain.com
The UNIX head and tail commands
The head and tail commands operate in
exactly the same fashion in UNIX and they are very useful for the
Oracle DBA who wants to view only a portion of a UNIX file.
The most common use of the tail command for
the Oracle DBA is monitoring a file as it becomes full. For
example, during an Oracle export, you might want to monitor the new
lines being added to the export log file. For this you can use
the tail ?f command to monitor the log:
root> tail
?f exp_customer.log
The tail command is also useful for looking
at new lines at the bottom of your Oracle alert log. For
example, the following command will display the last 50 lines of the
Oracle alert log:
root> tail
-100 $DBA/$ORACLE_SID/bdump/alert_$ORACLE_SID.log|more
Note that output of the tail command is
being piped to the more command so that you can view the alert log
one page at a time.
Next, let?s explore some important UNIX file
management commands.
File management in UNIX
The Oracle DBA is charged with the total
maintenance of all of the files that comprise the Oracle software.
As such, it is imperative that the Oracle DBA fully understand how
to manage UNIX files and directories. This management includes
allocating new files, removing old trace and dump files, and
managing the growth of the Oracle data files on the server.
The UNIX touch command
The UNIX touch command is used to create an
empty file with the proper owners and permissions. This is the
equivalent to the IEFBR14 utility on a mainframe computer, where a
file is created without any contents.
root>
touch test.exe
root> ls
-al test*
-rw-r-----
1 oracle dba
0 Aug 13 09:43 test.exe
Now let?s take a common Oracle example of
the touch command. First, we enter the UNIX pfile alias that we have
placed in our .profile file. This takes us to the location of
our Oracle alert log, and the ls ?al command shows us the file:
cheops*testsid-/export/home/oracle
> pfile
cheops*testsid-/u01/app/oracle/admin/testsid/pfile
> ls -al
total 26140
drwxr-xr-x 2 oracle dba
2048 Jul 18 13:36 .
drwxr-xr-x 9 oracle dba
2048 Feb 19 2001 ..
-rw-r--r-- 1 oracle dba
2301 Aug 22 13:01 inittestsid.ora
-rw-r--r-- 1 oracle dba
1840 Mar 13 23:00 inittestsid.ora.bkup
Next, we use the mv command to move the
alert log to another name. We do this so future grep commands
will not show us old results.
cheops*testsid-/u01/app/oracle/admin/testsid/pfile
> mv inittestsid.ora inittestsid.ora.old
Now, we can re-create an empty alert log
file with the touch command. Of course, this is not required
since Oracle will automatically re-allocate the alert log file the
first time that he needs to write an alert message:
cheops*testsid-/u01/app/oracle/admin/testsid/pfile
> touch inittestsid.ora
Now, the ls ?al command show us our old and
our new alert log files.
cheops*testsid-/u01/app/oracle/admin/testsid/pfile
> ls -al
total 26140
drwxr-xr-x 2 oracle dba
2048 Sep 4 16:57 .
drwxr-xr-x 9 oracle dba
2048 Feb 19 2001 ..
-rw-r--r-- 1 oracle dba
0 Sep 4 16:57 inittestsid.ora
-rw-r--r-- 1 oracle dba
1840 Mar 13 23:00 inittestsid.ora.bkup
-rw-r--r-- 1 oracle dba
2301 Aug 22 13:01 inittestsid.ora.old
Controlling UNIX file permission with
umask
UNIX has a default permission mask that is
used by default by everyone who accesses the Oracle server.
This permission mask is known as umask, and the value of umask
controls the default file permissions whenever you create a new UNIX
file.
Normally the umask is set system-wide in the
/etc/profile file so it applies to all users on the system.
However, often the Oracle DBA will override the default umask by
re-setting it in their login file (.profile or .cshrc).
The values for umask are different depending
upon whether the file is executable. The umask for the creation of
new executable files is calculated base don the value of umask.
In this case, we have set umask=022:
777 Default Permissions
-022 Subtract umask value, for example
-----
755 Permissions of new file
For executable files, the value of umask is
computed by taking the difference between 777 (read-write-execute)
and the actual value of umask. The following table
illustrates:
Umask value |
022 |
001 |
143 |
File permission |
755 |
776 |
637 |
Total |
777 |
777 |
777 |
In the example below, the default umask of
022 will leave a file with a permission of 755 (owner
read-write-execute, all others read-only) as shown below:
root>
umask
022
root>
touch test.exe
root> ls
-al test.exe
-rwxr-xr-x
1 oracle dba
0 Jan 22 05:36 test.exe
For another example, say we wanted all
Oracle owned file to be completely private, such that only oracle
could write to them and only members of the DBA group could read
them. We would want permissions of 740. To do this, we
will reset umask to 037:
root>umask
037
root>touch
test1.txt
root>ls
-al test1*
-rw-r-----
1 oracle dba
0 Aug 13 09:43 test1.txt
UNIX umask for Oracle text files
The umask for the creation of new text files
is calculated as follows:
666 Default Permissions
-022 Subtract umask mask, for example
-----
644 Permissions for new file
This example shows us that given the default
umask of 666, and subtracting our sample umask value of 022, new
text files are created with mode 644, which states that the owner
can read and write the file, while members of the group to which the
file belongs, and everyone else can only read the new file.
 |
If you like Oracle tuning, see the
book "Oracle
Tuning: The Definitive Reference", with 950 pages of tuning
tips and scripts.
You can buy it direct from the publisher for 30%-off and get
instant access to the code depot of Oracle tuning scripts. |