The Linux system is large and complex, summarized as a DBA, some basic management, network management, advanced applications, performance diagnostics, pipeline complex applications, hardware-related sensing commands need to master, this article, specifically as a DBA, must learn the 11 basic application commands.
1. ls command
The LS command is the most commonly used command in Linux, is the abbreviation of list, the missing LS command is to list the current directory, if LS specifies a different directory, it will display the list of files and folders in the specified directory.
Common usage (common parameters):
(1) Ls–l
Lists the details of files and directories in long format (only one file or directory information per line), with the following output:
[Email protected] single]$ ls-l
Total 14091544
-rw-r-----. 1 Oracle oinstall 5368717312 APR 10:50 sysaux02.dbf
-rw-r-----. 1 Oracle oinstall 9061015552 APR 08:05 users01.dbf
(2) Ls–a
List all the files and directories under the directory, the output is as follows:
[Email protected] single]$ ls-a
. .. SYSAUX02.DBF users01.dbf
(3) Ls–s
Lists the total size of the directory footprint, as well as the individual file names and their size in kilobytes (KB), with the following output:
[Email protected] single]$ ls-s
Total 14091544
5242892 sysaux02.dbf 8848652 users01.dbf
(4) LS–LH
In long format (only one file or directory information is displayed per line), and the total size of files and directories is displayed visually, the output is as follows:
[Email protected] single]$ LS-LH
Total 14G
-rw-r-----. 1 Oracle oinstall 5.1G APR 10:50 sysaux02.dbf
-rw-r-----. 1 Oracle oinstall 8.5G APR 08:05 users01.dbf
(5) LS–LRT
In long format (only one file or directory information is displayed per line), and the file and directory are sorted by the most time, the output is as follows:
[Email protected] single]$ LS-LRT
Total 14091544
-rw-r-----. 1 Oracle oinstall 9061015552 APR 08:05 users01.dbf
-rw-r-----. 1 Oracle oinstall 5368717312 APR 10:50 sysaux02.dbf
(6) Ls–lrth
Compared with "LS–LRT", the file size is displayed in a more intuitive way, with the following output:
[Email protected] single]$ Ls-lrth
Total 14G
-rw-r-----. 1 Oracle oinstall 8.5G APR 08:05 users01.dbf
-rw-r-----. 1 Oracle oinstall 5.1G APR 10:50 sysaux02.dbf
2. PWD command
The PWD command is the abbreviation for print working directory, and the basic feature is the printing of the current working directory.
Common usage (common parameters):
(1) PWD
Displays the absolute path of the current directory, with the following output:
[Email protected] oradata]$ pwd
/u01/oradata
(2) Pwd-p
Displays the physical path of the currently located directory. Because some directories are the result of link, the source path of link can be displayed with-p, and the output is as follows:
[Email protected] oradata]$ CD/ETC/INIT.D
[Email protected] init.d]$ pwd
/etc/init.d
[Email protected] init.d]$ pwd-p
/etc/rc.d/init.d
3. CD command
The CD command is one of the most commonly used commands in Linux for switching directory paths
Common usage (common parameters):
(1) CD
Back to your home directory, the output is as follows:
[Email protected] init.d]$ pwd
/etc/init.d
[[Email protected] init.d]$ CD
[Email protected] ~]$ pwd
/home/oracle
(2) cd–
Return to the directory where you came before this directory, and the output is as follows:
[Email protected] ~]$ pwd
/home/oracle
[Email protected] ~]$ Cd/u01/oradata/single
[Email protected] single]$ pwd
/u01/oradata/single
[Email protected] single]$ CD-
/home/oracle
[Email protected] ~]$ pwd
/home/oracle
(3) CD.
Go back to the top level directory and the output is as follows:
[Email protected] ~]$ pwd
/home/oracle
[Email protected] ~]$ CD.
[Email protected] home]$ pwd
/home
(4) CD. /..
Return to the top level two directory with the following output:
[Email protected] single]$ pwd
/u01/oradata/single
[Email protected] single]$ CD. /..
[Email protected] u01]$ pwd
/u01
(5) Cd/u01
Switch to the specified directory path, and the output is as follows:
[Email protected]/]$ cd/u01
[Email protected] u01]$ pwd
/u01
4. grep command
GREP is the abbreviation for global search Regular expression (RE) and is a powerful text search tool that can use regular expressions to search for text and print matching lines.
(1) grep command usage:
grep [OPTIONS] PATTERN [FILE ...]
grep [OPTIONS] [-E PATTERN |-f file] [FILE ...]
(2) Common parameters (OPTIONS)
-A: binary files are searched for data in the form of a text file
-C: Calculates the number of ' search string ' found
-I: Ignores case differences, so case is considered the same
-N: Output line number by the way
-V: Reverse selection, which shows the line without the ' search string ' content
-S: Do not display all rows that do not exist or have no matching text
--color: Will find the keyword part plus color display (values are: Never, always, auto three kinds)
(3) Common regular Expressions (PATTERN)
\: Ignores the original meaning of special characters in regular expressions.
^: matches the start line of the regular expression.
$: Matches the end line of the regular expression.
\<: Starts from the line that matches the regular expression.
\>: End of line to match regular expression.
[]: A single character, such as [a], a meets the requirements.
[-]: range, such as [A-z], i.e. A, B, C to Z all meet the requirements.
。 : all the individual characters.
*: There are characters, the length can be 0.
(4) Simple Use example
Common usage or Common parameters:
Displays the file containing the passwd character and the row where it is located:
[Email protected] admin]$ grep-n passwd *
catexp7.sql:170: (Name, UserID, passwd, Defrole, Datats, tempts, profile#,
Catzxs.sql:364:tmp: = Dbms_xdb. Createresource ('/sys/xs/roles/dbms_passwd.xml ', xsauthxsd);
Csminst.sql:25:rem YWu 02/19/04-fix bug 3434808, delete hard code passwd.
Take a line that contains 0-9 numbers:
[Email protected] admin]$ grep-n ' [0-9] ' Xsu111.sql
2:rem $Header: RDBMS/ADMIN/XSU111.SQL/MAIN/13 2010/06/06 21:49:30 Snadhika EXP $
4:rem Xsu111.sql
6:rem Copyright (c), and/or, Oracle, its affiliates.
5. Cat
Cat is a text file viewing and linking tool. To view the contents of a file, it is simpler to use cat, which is the name of the cat directly behind it.
Common usage (parameters):
(1) CAT/file name
The simplest cat usage that prints out the entire contents of the whole file
(3) cat–b/file name
Prints the contents of the entire file and numbers non-blank lines, starting with the line number 1, and the output is as follows:
[Email protected] admin]$ cat-b xsu111.sql |more
1 Rem
2 Rem $Header: RDBMS/ADMIN/XSU111.SQL/MAIN/13 2010/06/06 21:49:30 Snadhika EXP $
3 Rem
4 Rem Xsu111.sql
5 Rem
......
6, more
Similar to the cat command, but will be a page by page display to facilitate the user to read, and the most basic instruction is to press the space bar (space) to the next page, press the B key will be back to a page, but also the function of the search string (similar to VI)
[Email protected] admin]$ more Test.txt
Dddddddddddddddddddddddddddddd
7. Echo
The echo command displays the value of a character or variable on the screen.
Common usage:
(1) Output string
The string to be output is enclosed in double quotation marks, and the output is as follows:
[Email protected] admin]$ echo "Please wait 2 minute"
Please wait 2 minute
(2) Output variable value
Output the value of the $ORACLE_HOME environment variable, and the output is as follows:
[Email protected] admin]$ echo $ORACLE _home
/dba/oracle/product/11.2.0/db_1
8, hostname
Displays and sets the name of the current host system, only users with root privileges can set the host name.
Common usage:
(1) Display host name:
[Email protected] admin]$ hostname
Ol6-single
(2) Resolve the IP address of the host name:
If the/etc/hosts in the host name corresponding to the IP address of the information, or DNS can be parsed normally, the output is as follows:
[Email protected] ~]# hostname-i
192.168.2.150
(3) Temporarily set host name:
Temporarily set the hostname, modified, the hostname value in the/etc/sysconfig/network file remains unchanged, to permanently modify the hostname, you also need to modify the value of hostname in the/etc/sysconfig/network file. Here's how to use it:
[Email protected] ~]# hostname Lijunjie
[Email protected] ~]# hostname
Lijunjie
9. Touch
The touch command is used to fix the time to access and change the file to the current time or to a specified time, or to create a new file that does not exist
Common usage:
(1) Touch file name
Used to create a new file, if the file name already exists, the modified time of the modification is the current system time
[Email protected] admin]$ ls-l test.txt
-rw-r--r--. 1 Oracle oinstall APR 05:18 test.txt
[[Email protected] admin]$ Date
Sat APR 05:20:01 CST 2015
[email protected] admin]$ Touch test.txt
[Email protected] admin]$ ls-l test.txt
-rw-r--r--. 1 Oracle oinstall APR 05:20 test.txt
(2) Touch–r source file name destination file name
The time of the source file is updated to the target file, making two files the same time
[Email protected] admin]$ ls-l
-rw-r--r--. 1 Oracle Oinstall 363 SEP Listener.ora
-rw-r--r--. 1 Oracle oinstall APR 05:20 test.txt
[Email protected] admin]$ touch-r Listener.ora test.txt
[Email protected] admin]$ LS-LRT
-rw-r--r--. 1 Oracle Oinstall SEP test.txt
-rw-r--r--. 1 Oracle Oinstall 363 SEP Listener.ora
(4) Touch–t YYYYMMDDHHMI.SS
Changes the time of the file to the specified year, month, day, hour, minute. seconds
[Email protected] admin]$ ls-l test.txt
-rw-r--r--. 1 Oracle Oinstall SEP test.txt
[Email protected] admin]$ touch-t 201101012050.50 test.txt
[Email protected] admin]$ ls-l test.txt
-rw-r--r--. 1 Oracle Oinstall 1 test.txt
10, DF
The DF command is used to display detailed information about the file system and directory.
Common usage:
(1) Df–a
List all file systems and mount points, and the output is as follows:
[Email protected] admin]$ df-a
Filesystem 1k-blocks used Available use% mounted on
/dev/sda3 10321208 3403240 6393680 35%/
Proc 0 0 0-/proc
Sysfs 0 0 0-/sys
Devpts 0 0 0-/dev/pts
Tmpfs 507124 0 507124 0%/dev/shm
/DEV/SDA1 198337 50193 137904 27%/boot
/dev/sda2 39015880 27626000 9407928 75%/dba
None 0 0 0-/proc/sys/fs/binfmt_misc
SUNRPC 0 0 0-/var/lib/nfs/rpc_pipefs
/DEV/SDB1 51605436 15703408 33280624 33%/u01
(2) Df-h
Lists the file system and mount points that have been used to facilitate the identification of size information, easy to identify the size of the information is K, M, g format, the output results are as follows;
[Email protected] admin]$ df-h
Filesystem Size used Avail use% mounted on
/dev/sda3 9.9G 3.3G 6.1G 35%/
Tmpfs 496M 0 496M 0%/dev/shm
/DEV/SDA1 194M 50M 135M 27%/boot
/dev/sda2 38G 27G 9.0G 75%/dba
/DEV/SDB1 50G 15G 32G 33%/u01
Vim|vi
An example is a notepad on windows that edits the contents of a file or creates a new file. Powerful, as a DBA, must read the relevant information to master, not detailed in this.
11 Linux basic commands that a DBA must learn--mainly see parameters