Detailed explanation of Linux advanced commands for oracle users

Source: Internet
Author: User
Tags compare binary files file diff integer numbers md5 hash
(1) easily change owners, groups, and permissions

The following think describes how to easily change the owner, group, and permissions of chmod chown chgrp.

Suppose there are several files:

[Root @ bogon desktop] # ls-L total 4-rw-r -- r -- 1 Root 0 02-07 10:21 A-R-X-w -- w-1 root 0 02-07 b-RW-1 Root 0 02-07 C-rwxrwxrwx 1 Root 638 login. SQL

Now you need to change all permissions to match the permissions of login. SQL
Of course, the premise is that you do not know the permissions of a B c in advance or have thousands of files to be modified instead of a B c.
What should I do?

-- The reference option helps you solve problems

Run the following command to make login. SQL have the same permissions as:

[Root @ bogon desktop] # chmod -- reference a login. SQL [root @ bogon desktop] # ls-L total 4-rw-r -- r -- 1 Root 0 02-07 10:21 A-R-X-w -- w-1 Root 0 02- 07 B-RW-1 Root 0 02-07 C-RW-r -- 1 Root 638 login. SQL

The permissions of login. SQL are completely changed according to. You do not have to first obtain the permissions of

You can also use this technique to group members in files.
To make think belong to the same group as Oracle, run the following command:

[Root @ bogon Home] # ls-L total 24drwx ------ 7 Oracle oinstall 4096 02-06 oracledrwx ------ 3 oradev oinstall 4096 2012-07-15 oradevdrwx ------ 4 think 4096 2012-07-23 think [root @ bogon home] # chgrp -- reference Oracle think [root @ bogon Home] # ls-L total 24drwx ------ 7 Oracle oinstall 4096 02-06 oracledrwx ------ 3 oradev oinstall 4096 2012-07-15 oradevdrwx ------ 4 think oinstall 4096 think

The method for modifying the reorganization also applies to the owner.

[Root @ bogon Home] # ls-L total 24drwx ------ 7 Oracle oinstall 4096 02-06 oracledrwx ------ 3 oradev oinstall 4096 2012-07-15 oradevdrwx ------ 4 think oinstall 4096 2012-07-23 think [root @ bogon home] # chown -- reference Oracle think [root @ bogon Home] # ls-L total 24drwx ------ 7 Oracle oinstall 4096 02-06 oracledrwx ------ 3 oradev oinstall 4096 2012-07-15 oradev

Tips for oracle users

This technique is very useful for porting. During the porting, You can (and possibly should) install files as different user identities
And later transfer these files to the regular Oracle software owner


(2) Detailed description of relevant documents

The LS command and many parameters provide some useful file information.
Another unfamiliar command, stat, provides more useful information.

[oracle@Think ~]$ cd $ORACLE_HOME/bin[oracle@Think bin]$ stat oracle  File: `oracle'  Size: 93362427        Blocks: 182552     IO Block: 4096   regular fileDevice: 802h/2050d      Inode: 1557452     Links: 1Access: (6751/-rwsr-s--x)  Uid: (  501/  oracle)   Gid: (  502/oinstall)Access: 2013-02-07 10:55:28.000000000 +0800Modify: 2012-07-15 16:33:49.000000000 +0800Change: 2012-07-15 16:36:54.000000000 +0800

Note the information obtained by using this command: Except for the normal file size (you can also use the LS-l command)
You have also obtained the number of blocks occupied by the file.
Generally, Linux blocks are 512 bytes in size. Therefore, a 93362427-byte file occupies (93362427/512 =) 182348.49 blocks.
Because all blocks are fully occupied, this file uses blocks with some integer numbers, and you can obtain the exact number of blocks without guessing.

You can also obtain the GID and uid of the file ownership from the above output, and the octal representation of the permission (6751)
To restore a file to the same permissions that it currently has, you can use chmod 6751 Oracle instead of displaying spelling permissions.

The most useful part of the above output is the file access timestamp information.
The output shows that the file was accessed at 10:55:28, (displayed next to "access)
This is the time someone started to use the database. The modification time of this file is 16:33:49 (displayed next to "modify)

The modifier-F of the STAT command displays information about the file system rather than the file:

[oracle@Think bin]$ stat -f oracle  File: "oracle"    ID: 0        Namelen: 255     Type: ext2/ext3Block size: 4096       Fundamental block size: 4096Blocks: Total: 2480156    Free: 769982     Available: 641965Inodes: Total: 2560864    Free: 2394828

Tips for oracle users

When you reconnect to Oracle (usually executed during patch installation), the name of the existing executable file will be changed to another name before a new executable file is created.
For example, you can use the following command to relink all utilities

Relink utilities

This command re-compiles the SQL plus executable file and performs other operations.
It name the existing Executable File sqlpluso. If re-compilation fails for some reason
The relink process renames sqlpluso to sqlplus and revokes the change.
Similarly, if a functional problem is found after the patch is applied, You can manually rename the file to quickly remove the patch.

[oracle@Think bin]$ stat sqlplus*  File: `sqlplus'  Size: 8868            Blocks: 32         IO Block: 4096   regular fileDevice: 802h/2050d      Inode: 1565800     Links: 1Access: (0751/-rwxr-x--x)  Uid: (  501/  oracle)   Gid: (  502/oinstall)Access: 2013-02-07 10:14:38.000000000 +0800Modify: 2012-07-15 16:34:00.000000000 +0800Change: 2012-07-15 16:36:54.000000000 +0800  File: `sqlplusO'  Size: 0               Blocks: 8          IO Block: 4096   regular empty fileDevice: 802h/2050d      Inode: 1560598     Links: 1Access: (0755/-rwxr-xr-x)  Uid: (  501/  oracle)   Gid: (  502/oinstall)Access: 2012-07-15 16:27:10.000000000 +0800Modify: 2005-06-30 19:23:56.000000000 +0800Change: 2012-07-15 16:36:54.000000000 +0800


The output shows that the modification time of sqlpluso is, while that of sqlplus is.
This time is also the time when the sqlpluso status changes
The output indicates that the original version of sqlplus has been running properly from.
If you want to diagnose some functional problems, this information will be a very good start point.
Except for file changes, if you know the permission change time, You can associate it with any detected functional problems.

Another important output is the file size. Different files have different sizes.


(3) file type

How do I know the file type when viewing a file? The command file can display the file type. For example:

[Oracle @ think bdump] $ file alert_orcl.logalert_orcl.log: the ASCII English text file alert_orcl.log is an ASCII text file. For more examples, see [Oracle @ think DBS] $ file spfileorcl. ora. zspfileorcl. ora. z: Bzip2 compressed data, block size = 900 K


This example indicates that the file is compressed, but how do I know the compression type of the file? One way is to decompress the file and run it again.
But this is actually almost impossible. A simple method is to use the parameter-Z:

[oracle@Think dbs]$ file -z spfileorcl.ora.zspfileorcl.ora.z: POSIX tar archive (bzip2 compressed data, block size = 900k)

Another way is to display symbolic links:

[root@Think Desktop]# file a_softlink a_softlink: symbolic link to `a'

Although this method is useful, what type of file is it pointing? You can use option-L instead of running the file again:

[root@Think Desktop]# file -L a_softlink a_softlink: ASCII text

This example clearly indicates that the file type is text.


Tips for oracle users

Assume that you want to search for a trace file in the target directory of the user dump, but you do not know whether the file is in another directory and only exists in the form of a symbolic link
Or whether a person compresses the file (or even rename the file), you know one thing:
This file must be an ASCII file. The following shows how to perform the operation:
File-LZ * | grep ASCII | cut-d ":"-F1 | xargs LS-LTR
This command will check ASCII files (even if they are compressed) and list them in chronological order


(4) comparison file diff

How can I determine whether two files are the same? There are multiple methods, and each method has its own advantages

The simplest diff command is diff, which is used to display the differences between two files. The content of the two files is as follows:

[root@Think Desktop]# cat bMy name is Thinkhello world[root@Think Desktop]# cat cYour name is Thinkhello world

Use the diff command to understand the differences between the two files, as shown below:

[root@Think Desktop]# diff b c1c1< My name is Think---> Your name is Think

In the above output, "<" in the first column indicates that the row is located in the file (B) mentioned above.
">" In the first column indicates that the row is located in the second file (that is, c ).
Output the character 1C1 in the first line. In order to make B and C the same, the first line in B needs to be modified. The modified row number can be found in the first line in C.

Another option-y shows the same output, but the output is displayed side by side:

[root@Think Desktop]# diff -y b c -W 120My name is Think                                           |    Your name is Thinkhello world                                                     hello world

-W is optional; it only indicates that the command uses screen output with a width of 120 characters, which is useful for files containing long lines.
If you only want to know whether the files are different, you can use the-Q option.

[root@Think Desktop]# diff -q b cFiles b and c differ[root@Think Desktop]# diff b d[root@Think Desktop]# 

Because file B D is the same, no output

If you want to write a shell script, it may be useful to generate output that can be analyzed using the following method. -U option:

[root@Think Desktop]# diff -u b c--- b   2013-02-07 17:23:54.000000000 +0800+++ c   2013-02-07 17:24:32.000000000 +0800@@ -1,2 +1,2 @@-My name is Think+Your name is Think hello world

The above output shows the content of the two files, but does not show repeated content. The + and-in the first column indicate the rows in the file.
None of the characters in the first column indicate the content that exists simultaneously in the two files.
This command can recognize spaces. To ignore spaces, use the-B option and use the-B Option to ignore blank lines. Use-I to ignore case sensitivity.

Diff can also be applied to directory: Diff dir1 dir2

Option-R will recursively enter each subdirectory to compare files and report differences between files with the same name


Tips for oracle users

A common usage of diff is to differentiate different init. ora files. One of the best practices is to copy and rename files before I change them.
For example, copy initorcl. ora and rename it as initorcl. ora. Bak. A simple diff between all versions of the file can be used quickly.
Specifies the content that has been changed and the time of the change.

This is a very powerful command for managing the oracle root directory. Best Practice: I never update the oracle root directory when applying patches
For example, assume that the current Oracle version is 10.2.0.1. ORACLE_HOME may be/u01/APP/Oracle/product/10.2/db_1
When you need to update it to 10.2.0.2, I will not patch this oracle root directory. Instead, I will go to/u01/APP/Oracle/product/10.2/db_2
Start a new installation on this directory and patch the root directory.
After you are ready, run the following command:

# Sqlplus/As sysdbasql> shutdown immediatesql> exit # export ORACLE_HOME =/u01/APP/Oracle/product/10.2/DB2 # export Path = $ ORACLE_HOME/bin: $ path # sqlplus/As sysdbasql> @ $ ORACLE_HOME/rdbms/admin/catalog... and so on.

The purpose of this method is not to destroy the original oracle root directory, so I can easily restore it when a problem occurs.
This also means that the database is shut down and started again, and can be completed instantly.
If I install the patch directly to the oracle root directory, the database must be closed for a long time (the entire duration of the patch application ).
In addition, if the patch application fails for some reason, you do not have to clear the oracle root directory.

So since there are multiple oracle root directories, how can I view the changes in the content? The method is actually very simple. You can run the following command:

Diff-r/u01/APP/Oracle/product/10.2/db_1/u01/APP/Oracle/product/10.2/db_2 | grep-V common

This command shows the differences between two oracle root directories and the differences between files with the same name
Some important files (such as tnsnames. ora, listener. ora, and sqlnet. ora) are not significantly different.
However, if the difference is great, I need to know the reason for the difference.


CMP for comparing objects in a Comparative Statement

CMP is similar to DIFF:

[root@Think Desktop]# cmp b cb c differ: byte 1, line 1

If there is a difference, the output is returned. You can use this output to identify where the file may be different.
Like diff, CMP has many options. The most important one is-S, which returns only one code:
● If the file is the same, 0 is returned.
● If the file is different, 1 is returned.
● If the comparison cannot be performed, a non-0 number is returned.
For example:

[root@Think Desktop]# cmp -s b c[root@Think Desktop]# echo $?1

Special variable $? Indicates that the returned code is from the command executed last time.

This CMP attribute is very useful for shell scripts.
In shell scripts, you only want to check whether there are differences between the two files, instead of checking what the difference is.
Another important purpose of this command is to compare binary files, while diff may not be reliable for binary files.


Tips for oracle users

As mentioned above, when you re-link the oracle executable file, the old version will be retained until it is overwritten.
Therefore, when re-linking, the executable file sqlplus is renamed to sqlplus0, and the newly compiled sqlplus is placed in $ ORACLE_HOME/bin.
So how can we determine the difference between the created sqlplus? Run the following command:

# cmp sqlplus sqlplusOsqlplus sqlplusO differ:byte 657, line 7

If the check size is:

# ls -l sqlplus*-rwxr-x--x    1 oracle   dba          8851 Aug  4 05:15 sqlplus-rwxr-x--x    1 oracle   dba          8851 Nov  2  2005 sqlplusO

Even if the two examples have the same size, CMP can prove that the two programs are different.


Token file Verification 

Md5sum this command will generate the file's 32-bit MD5 Hash Value

[root@Think Desktop]# md5sum b2f96b2388e690eaa463d2610954a9e05  b

Two files with the same checksum can be considered the same
The purpose of this command is not only to compare files. It also provides a mechanism to ensure file integrity.

Assume that you have two important files to be protected, file1 and file2. you can use the -- check option to check and ensure that the files are not changed.
First, create a checksum file for these important files and save it securely:

Md5sum file1 file2> f1f2

If you want to check whether these files remain unchanged, perform the following operations:

Md5sum -- check f1f2


Tips for oracle users

Md5sum is a very useful and powerful command for security implementation.
Some configuration files you manage (such as listener. ora) are very important for a successful Oracle infrastructure. Any modifications may cause downtime.
Do not believe that the files mentioned by others have not been changed. use MD5 checksum to run the command.
Create a checksum file and re-create it each time you change the execution plan
As part of compliance, run the md5sum command to check the file
If someone accidentally updates one of these important files, you can capture changes immediately.

Similarly, you can create MD5 checksum for All executable files in $ ORACLE_HOME/bin and compare them continuously to capture unauthorized modifications.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.