As a DBA, you must learn the following 11 basic Linux commands that will not die: dbalinux
Most databases run on Linux and UNIX platforms. As the computing power of the X86 platform approaches or even exceeds that of minicomputers, and with the tide of IOE removal, more and more databases run on the Linux platform.
The Linux system is huge and complex. As a DBA, some basic management, network management, advanced applications, performance diagnostics, complex pipeline applications, and hardware-related sensing commands need to be mastered, this article focuses on 11 basic application commands that must be learned as a DBA.
1. ls command
The Ls command is the most commonly used command in Linux and is short for list. By default, the ls command is used to list the current directory. If ls specifies other directories, the list of files and folders in the specified directory is displayed.
Common usage (common parameters ):
(1) ls-l
List detailed information about files and directories in long format (only one file or directory information is displayed per line). The output result is as follows: [Oracle @ ol6-single single] $ ls-l Total 14091544 -Rw-r -----. 1 oracle oinstall 5368717312 Apr 10 sysaux02.dbf -Rw-r -----. 1 oracle oinstall 9061015552 Apr 10 users01.dbf |
(2) ls-
List all files and directories in the directory. The output result is as follows: [Oracle @ ol6-single single] $ ls- ... Sysaux02.dbf users01.dbf |
(3) ls-s
List the total space occupied by the Directory and the names and sizes of each file (unit: KB). The output result is as follows: [Oracle @ ol6-single 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 the file and directory is displayed in an intuitive way. The output result is as follows: [Oracle @ ol6-single single] $ ls-lh Total 14G -Rw-r -----. 1 oracle oinstall 5.1G Apr 10 sysaux02.dbf -Rw-r -----. 1 oracle oinstall 8.5G Apr 10 users01.dbf |
(5) ls-lrt
In long format (only one file or directory information is displayed per line), and files and directories are sorted by the most time. The output result is as follows: [Oracle @ ol6-single single] $ ls-lrt Total 14091544 -Rw-r -----. 1 oracle oinstall 9061015552 Apr 10 users01.dbf -Rw-r -----. 1 oracle oinstall 5368717312 Apr 10 sysaux02.dbf |
(6) ls-lrth
Compared with "ls-lrt", the file size is displayed in a more intuitive way. The output result is as follows: [Oracle-ol6-single single] $ ls-lrth Total 14G -Rw-r -----. 1 oracle oinstall 8.5G Apr 10 users01.dbf -Rw-r -----. 1 oracle oinstall 5.1G Apr 10 sysaux02.dbf |
2. pwd command
The pwd command is short for Print Working Directory. The basic function is to Print the current Working Directory.
Common usage (common parameters ):
(1) pwd
The absolute path of the current directory is displayed. The output result is as follows: [Oracle @ ol6-single oradata] $ pwd /U01/oradata |
(2) pwd-p
Displays the physical path of the current directory. Because some directories are link results, you can use-P to display the link Source Path. The output result is as follows: Oracle @ ol6-single oradata] $ cd/etc/init. d [Oracle @ ol6-single init. d] $ pwd /Etc/init. d [Oracle @ ol6-single init. d] $ pwd-P /Etc/rc. d/init. d |
3. cd command
The cd command is one of the most common commands in linux and is used to switch directory paths.
Common usage (common parameters ):
(1) cd
Return to your HOME directory and the output result is as follows: [Oracle @ ol6-single init. d] $ pwd /Etc/init. d [Oracle @ ol6-single init. d] $ cd [Oracle @ ol6-single ~] $ Pwd /Home/oracle |
(2) cd-
Return the directory that is located before entering the directory. The output result is as follows: [Oracle @ ol6-single ~] $ Pwd /Home/oracle [Oracle @ ol6-single ~] $ Cd/u01/oradata/single [Oracle @ ol6-single single] $ pwd /U01/oradata/single [Oracle @ ol6-single single] $ cd- /Home/oracle [Oracle @ ol6-single ~] $ Pwd /Home/oracle |
(3) cd ..
Return to the upper-level directory. The output result is as follows: [Oracle @ ol6-single ~] $ Pwd /Home/oracle [Oracle @ ol6-single ~] $ Cd .. [Oracle @ ol6-single home] $ pwd /Home |
(4) cd ../..
Return the two levels of directories. The output result is as follows: [Oracle @ ol6-single single] $ pwd /U01/oradata/single [Oracle @ ol6-single single] $ cd ../.. [Oracle @ ol6-single u01] $ pwd /U01 |
(5) cd/u01
Switch to the specified directory path. The output result is as follows: [Oracle @ ol6-single/] $ cd/u01 [Oracle @ ol6-single u01] $ pwd /U01 |
4. grep command
Grep is short for global search regular expression (RE). It is a powerful text search tool that uses regular expressions to search for text and print matching rows.
(1) grep command usage:
Grep [OPTIONS] PATTERN [FILE...] Grep [OPTIONS] [-e PATTERN |-f FILE] [FILE...] |
(2) common parameters (OPTIONS)
-A: searches binary files for data using text files. -C: calculates the number of times the 'search string' is found. -I: Case sensitivity is ignored, so the case sensitivity is the same. -N: returns the row number by the way. -V: reverse selection, that is, the row without the 'search string' content is displayed. -S: do not show all rows that do not exist or do not match the text -- Color: add color to the keywords (values include never, always, and auto) |
(3) Common Regular Expressions (PATTERN)
\: Ignore the original meaning of special characters in regular expressions. ^: Match the start line of the regular expression. $: Matches the end row of the regular expression. \ <: Starts from the row that matches the regular expression. \>: Ends with the row that matches the regular expression. []: A single character. For example, [A] indicates that A meets the requirements. [-]: Range, such as [A-Z], that is, A, B, C Until Z all meet the requirements. . : All single characters. *: It can contain 0 characters. |
(4) simple use of instances
Common usage or parameters:
Display the file containing passwd characters and Its row: [Oracle @ ol6-single 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. Extract the rows that contain 0-9 numbers: [Oracle @ ol6-single 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) 2007,201 0, Oracle and/or its affiliates. |
5. cat
Cat is a tool for viewing and connecting text files. View the content of a file. It is easy to use cat, that is, the file name is directly followed by cat.
Common usage (parameters ):
(1) cat/file name
The simplest cat usage: print out all the content of the entire file in the original file. |
(3) cat-B/file name
Print the content of the entire file and number non-blank rows. The output result is as follows: [Oracle @ ol6-single 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 cat commands, but it will be displayed on one page for users to read on one page, and the most basic command is to press space to display on the next page, press the B key to display the back page and search for strings (similar to vi)
[Oracle @ ol6-single admin] $ more test.txt Dddddddddddddddddddddddddddddddddddddd |
7. echo
The Echo command displays the values of characters or variables on the screen.
Common usage:
(1) Output string
The string to be output is enclosed in double quotation marks. The output result is as follows: Oracle @ ol6-single admin] $ echo "please wait 2 minute" Please wait 2 minute |
(2) output variable value
Output the value of the $ ORACLE_HOME environment variable. The output result is as follows: [Oracle @ ol6-single admin] $ echo $ ORACLE_HOME /Dba/oracle/product/11.2.0/db_1 |
8. hostname
Display and set the name of the current host system. Only users with ROOT permission can set the host name.
Common usage:
(1) display the Host Name:
[Oracle @ ol6-single admin] $ hostname Ol6-single |
(2) Resolve the IP address corresponding to the Host Name:
The premise is that/etc/hosts contains information about the IP address corresponding to the host name, or the DNS can be properly parsed. The output result is as follows: [Root @ ol6-single ~] # Hostname-I 192.168.2.150 |
(3) temporarily set the Host Name:
Set the host name temporarily. After modification, the HOSTNAME value in the/etc/sysconfig/network file remains unchanged. to modify the host name permanently, you also need to modify the hostname value in the/etc/sysconfig/network file as follows: [Root @ ol6-single ~] # Hostname lijunjie [Root @ ol6-single ~] # Hostname Lijunjie |
9. touch
The Touch command is used to repair and modify the current time or specified time of the file, or to create a new file that does not exist.
Common usage:
(1) touch file name
Creates a new file. If the file name already exists, the modification time of the file is the current system time. [Oracle @ ol6-single admin] $ ls-l test.txt -Rw-r --. 1 oracle oinstall 31 Apr 11 05:18 test.txt [Oracle @ ol6-single admin] $ date Sat Apr 11 05:20:01 CST 2015 [Oracle @ ol6-single admin] $ touch test.txt [Oracle @ ol6-single admin] $ ls-l test.txt -Rw-r --. 1 oracle oinstall 31 Apr 11 05:20 test.txt |
(2) touch-r source file name target file name
Update the source file time to the target file so that the time of the two files is the same [Oracle @ ol6-single admin] $ ls-l -Rw-r --. 1 oracle oinstall 363 Sep 10 2014 listener. ora -Rw-r --. 1 oracle oinstall 31 Apr 11 05:20 test.txt [Oracle @ ol6-single admin] $ touch-r listener. ora test.txt [Oracle @ ol6-single admin] $ ls-lrt -Rw-r --. 1 oracle oinstall 31 Sep 10 2014 test.txt -Rw-r --. 1 oracle oinstall 363 Sep 10 2014 listener. ora |
(4) touch-t yyyymmddhhmi. ss
Change the file time to the specified year, month, day, hour, and minute. Second. [Oracle @ ol6-single admin] $ ls-l test.txt -Rw-r --. 1 oracle oinstall 31 Sep 10 2014 test.txt [Oracle @ ol6-single admin] $ touch-t 201101012050.50 test.txt [Oracle @ ol6-single admin] $ ls-l test.txt -Rw-r --. 1 oracle oinstall 31 Jan 1 2011 test.txt |
10. df
The Df command is used to display detailed information about the file system and directory.
Common usage:
(1) df-
List all file systems and mount points. The output result is as follows: [Oracle @ ol6-single admin] $ df- 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
List existing file systems and mount points and size information that are easy to identify. The size information is in K, M, and G formats. The output result is as follows; [Oracle @ ol6-single admin] $ df-h Filesystem Size Used Avail Use % Mounted on /Dev/sda3 9.9 GB 3.3G 6.1G 35%/ Tmpfs 496 M 0 496 M 0%/dev/shm /Dev/sda1 194 M 50 M 135 M 27%/boot /Dev/sda2 38G 27G 9.0G 75%/dba /Dev/sdb1 50G 15G 32G 33%/u01 |
11 vim | vi
Like Notepad on Windows, it is used to edit the content of a file or create a new file. Powerful functions. As a DBA, you must read the relevant documents and do not detail them here.
Author: LI Junjie (Network Name: Step-by-Step), engaged in "system architecture, operating system, storage device, database, middleware, application" six levels of systematic performance optimization work
Join the system performance optimization professional group to discuss performance optimization technologies. GROUP: 258187244