Linux Learning Notes

Source: Internet
Author: User
Tags control characters echo 7 exit in string to file

. Current directory
/root directory
~ $HOME Directory

Backslash \ Tell s H e l l The command has not ended

Touch: Create a new file

chmod u+l filename:l permissions, lock file filename, other users cannot access this file
Absolute mode: 4: Read 2: Write 1: Execute. Example: 744 <==>-rwxr--r--
Set all file permissions in this directory at once: chmod 744 *; chmod g-w *; chmod a+w *
Use the-R option to set together with the files under subdirectories: Chmod-r 664/usr/local/home/dave/*

The Read permission bit for a directory means that the contents can be listed. The Write permission bit means that the file can be created in this directory. Execute a permission bit means to search for and access the directory

Chown: Change file owner (similar to CHGRP command)

The system does not allow you to execute permissions when creating a text file, you must manually add this permission with the chmod command after creation (directory allow)
Umask: The command determines the default mode in which you create the file, you can modify the default mode with Umask 022, and view the default mode with Umask

Symbolic links exist in two different types of links, soft links and hard links, and only soft links are discussed. A soft link is actually a pointer to a file.
Establish link command: LN [-S] source_path Target_path

Find: It can traverse the current directory and even the entire file system to find some files or directories. $ find. -name "*.txt"-print

Echo: Echoing echo "Test"
echo "TEST" > FileName redirect string to file
echo "test2" >> filename appends the string to the file without overwriting the original content

READ: Reads information from the keyboard or text and assigns a variable. $read name $ "test" assigns the test string to the name variable

Cat: Displays the contents of a file, creates a file, and can also use it to display control characters.
CAT-V filename Display control characters
Cat File1 file2 ... Show File1 file2 ... The contents of such files
Cat file1 file2 > File3 redirect File1, file2 to File3 file
Cat > FileName: Enter text into the filename file to ctrl-d end

Pipeline: You can pass the output of one command to another command as input through a pipeline.
ls | Grep-i test: Search for files with file names similar to test and show them

Tee: It transports one copy of the output to the standard output and the other copy to the corresponding file. If you want to see the output at the same time, also save it to a file,
Then this is the right order. Tee [-a] filename. -A: Append to the end of filename file
Ls-l | TEE-A FileName: Appends the output of the ls-l command to the end of the filename file

grep: Pattern lookup on a text file
-I: Ignore case
-C: Output only the count of matching rows
-V: Displays all lines that do not contain matching text
-N: Displays matching line numbers, contents
If you want to find the string "sort" in all. doc files in the current directory: grep "Sort" *.doc
Grep-c "Sort" *.doc returns: 4 that is, 4 rows containing the "sort" string

If you want to extract the record so that it is not 48 at the beginning of the line, you can use the ^ mark in square brackets to indicate that the query starts at the beginning. grep ' ^[^48] ' filename
Look for a 5-character string whose start is B-End is F: grep ' b...f ' filename
Use a combination of ^ and $ to query for blank lines. Use the-n parameter to display the actual number of rows: grep ' ^$ ' filename

awk: Formatting a message or extracting a packet from a large text file, awk is the hardest of all shell filtering tools
An built-in variable of Nf:awk that represents the number of fields per row
Several uses of NF:
1. Exclude blank lines. (The line is not printed because the nf=0,0 is false because of empty lines)
awk NF filename
2. Do not output the following two fields: awk ' nf-=2 ' filename
Do not output the first two fields: Awk ' {for (i=3;i<nf;i++) printf ('%s ', $i);p rint $NF} ' filename

Variable assignment: $weekbegin = "20110701"
Display variable: $echo ${weekbegin} or Echo $weekbegin
Clear variable Value: $unset weekbegin
Use the SET command to display all locally defined shell variables. $set
To display the variable side-by: $echo ${variable 1}${variable 2}
If a variable value is set, it is used and if not set, the new value is taken. $color = "Blue"
$echo "The sky is ${color:-grey} today"
The sky is blue today

Set a read-only variable, you cannot change its value after setting it, otherwise error:
$AA = "Test" $echo ${aa} $readonly aa $aa = "Add" (Error message) =>ksh:aa:is Read Only
To view all read-only variables, use the command readonly.

Traditionally, all environment variables are capitalized. Environment variables must be exported with the Export command before they are applied to the user process.
Use method One: Variable-name=value;export variable-name between two commands is a semicolon, value does not enclose double quotation marks. You can also write this:
Export Variable-name
Use the ENV command to view all environment variables. $env
To clear environment variables with the unset command: $unset variable-name

Home directory, you can simply use the CD command to enter it. $echo $HOME $/db2home/asiainfo $cd $pwd $/db2home/asiainfo

$ path= $HOME/bin:.:/ Bin:/usr/bin;export PATH
Using the above example, first find the H O M e/b i n directory, then the current working directory, then the/b i n, and finally the/U s r/b i n.

$# the number of arguments passed to the script
$* displays all parameters passed to the script in a single string. Unlike positional variables, this option parameter can be more than 9
$$ script runs the current process i D
$! Process I D of the last process running in the background
[Email protected] and $ #相同, but use quotation marks and return each parameter in quotation marks
$-Display the current option for S H e l L with the same function as the S e T command
$? Displays the exit status of the last command. 0 means there is no error, and any other value indicates an error.

Anti-quotes are used to set the output of system commands to variables. $echo ' Date ' $ A.D. September 22, 2011 Thursday 13:57 47 seconds
$mydate = ' Date ' $echo $mydate $ A.D. September 22, 2011 Thursday 13:57 47 seconds
In another example, enclose the inverted quotation marks in double quotes: $echo "Today is ' Date '" $today was A.D. September 22, 2011 Thursday 13:57 47 seconds

Print the current number of users on the system: $echo "There is" who | Wc-l ' Users on the system '
When using the command E x P R, there is an error in multiplication with *, and a backslash before * is correct.
Error: $expr 12*12
Correct: $expr 12\*12

Condition test: 17 Chapters
Test value: ["number" Numeric_operator "numbers"]
The Numeric_operator can be:
-eq values are equal. Equal
-ne values are not equal. Not-equal
-GT the first number is greater than the second number. Greater-than
-lt The first number is less than the second number. Less-than
-le The first number is less than or equal to the second number. Less equal
-ge the first number is greater than or equal to the second number. Greater equal
If [$?-gt 1-o ' expr length $ '-lt 10]
-a logic with, both sides of the operator are true, the result is true, otherwise false.
-O logic or, the operator is true on either side, the result is true, otherwise false.
! Logical No, the condition is false and the result is true.

awk: The most basic function is to browse and extract information in a file or string based on the specified rules.
Begin: Print Report header end: Print report footer (begin mode and end mode)
awk ' BEGIN {print ' ID filed1 filed2\n--------------------------} {print $ "\ t" $ "T" $ $} END {print "Game Over"} ' myfile
ID filed1 Filed2
One AA AA ' a
2313 LSJFO Llasdolli
BB bb.fglsldi
5 EE eees/fd
6 FF Fffew
Game Over

The Lappend command is used to append new elements to the end of the list
%lappend new {3 4} "5" {6} 7
= 1 2 {3 4} 5 6 7; #单个词的元素的双引号和花括号被剥离了

When you use the Find command, you may want to match all the files and find them in the subdirectory.
In the following example, the Find command starts at the root of the file system and looks for a named CON. File.
It will first match all the files and then go to the subdirectory to find them. (-depth-print can be omitted)
$ find/-name "CON. FILE "-depth-print
Queries the current directory and its subdirectories starting from the current directory $ find. -name "Con.file"

#将This is a test file written in MyFile.txt
Set filename "/db2home/asiainfo/prov_stat/report/myfile.txt"
Set FD [Open $filename W]
Puts $FD "This is a test file"

SED usage:
Sed-n ' 2p ' myfile: Displays the second line of content in the file myfile, the-n option, which displays the print anchor line.
Sed-n ' 1,3p ' myfile: Print rows
Sed-n '/ff/' P myfile: match the word FF and print this line
Sed-n ' 4,/ff/' P myfile: line number and pattern co-query
Sed-n '/\$/' P myfile: match meta character $ before, first use/escape
Sed-n ' 1, $p ' myfile: Displays the entire file content. $: Last line. From the first line to the last row.
Sed ' 1,17d ' delete line 1th to 17th

1. Create an SED script file: $pg append.sed
/company/a\ #: You can use line numbers instead of patterns/company/such as: 4 a\
The Test text!
2. Add Execute Permissions: $chmod u+x append.sed
3. Run the sed file: $append. sed myfile
Explanation: Find the line of pattern company in the MyFile file and append (a\) One line after this line the test text!
However, the contents of the MyFile file do not change, because the SED script does not manipulate the file, but instead operates a copy of it, and if you want to run the result, the runtime redirects to another file

Another: Insert text before BBBB line line
This is added!

Replace line: Replace AAAA row with abcdef

Replace text: (instead of replacing a line, only the text on the match is replaced)
Sed ' s/bb/bbbb/' myfile
Sed ' s/bb/bbbb/g ' myfile

Sed ' 2d ' myfile: Deletes the second row of data. D: Delete. is also a copy of the operation, not the actual source file.

To transfer values from the shell to sed:
To pass values to sed from the command line, it is worth noting that double quotation marks are used, otherwise the function does not execute.
$NAME = ' It is a go situation '
$echo $NAME | Sed "s/go/$REPLACE/g"
Output: It is a GO situation

To set the shell variable from the SED output:
Setting the shell variable from the SED output is a simple replacement process. Using the above example, create the shell variable New-name to save the output of the above sed example.
$NAME = ' It is a go situation '
$NEW _name= ' echo $NAME | Sed "/s/go/$REPLACE/g" '
$echo $NEW _name
Output: It is a GO situation

Sort < bb > Aa.out # # #: Each line in the BB file is sorted alphabetically, then the results are output to the Aa.out file (bb as the input file, aa.out as the output file)
$ mail Louise < Contents.txt # # # #: When you send a message, you can send the contents of a file in a redirected manner. In the following example, the user
Louise will receive a message containing the contents of the file Contents.txt:

For example, by/usr/share/doc to/usr/share/man under
, it can be written as: "CD. /man "This is how the relative path is written!" Relative path meaning led "relative to the current work 弽
Path! 』

-P: Directly set up the desired directory TEST3 and the upper directory recursively.

Force Delete Directory Machine subdirectory: rm-r test1 (/test1/test2/test3 delete all)

Ls-d: Lists only the directory itself and does not list files in the directory
-R: Listed along with subdirectory content
AA* Dw_week.del fzdbb/myfile sqlnet.log* test.tcl tmp.sql xinhua/


-T: Sort by time (e.g.: ls-lt: Displayed in long format and sorted by time, most recent time file is first)

Cp-i: If the target file (destination) already exists, the action will be asked before overwriting (common)
-P: Copy the past with the attributes of the archive, instead of using the default properties (Backup common)
-R: Recursive continuous replication, used for directory replication behavior, (commonly used) such as: Ls-r./test./test1 (even if the Test1 directory does not exist beforehand and no problem)

Content query, there are more instructions can be used, CAT/MORE/LESS/TAIL/TAC and so on
Cat: Starting from the first line
TAC: Starting from the last line (can be seen as the TAC is backwards written by cat)
NL: By the way output line number
MORE: A page-by-page display
Space: Turn down one page
Enter: Turn down one line
/string: Search down the string
: F Displays the file name and the number of rows currently displayed
Q Leave More now
b page Back
Less: Similar to more, but less can page forward
Space: Turn down one page
[PageDown]: Flip one PAGE Down
[PageUp]: Flip up one page;
/string: Search down the string
String: Search up the string
N: Repeat the previous search (with/or?)
N: Reverse Duplicate previous search (with/or? related)
Q: Leave
Head: Show the first few lines
Tail: Show last few lines
-B: Show line numbers
-N: Show line numbers (blank lines also have line numbers, unlike-B)
-V: Lists some special characters that can't be seen

Which: the directory under which an instruction is placed. For example: Which LS result: usr/bin/ls
Type: Details of an instruction (directory/alias of which command aliases) such as: Type LL ==>ll is a alias for ls-l

Cut how to use:
[Email protected] ~]# echo $PATH
[Email protected] ~]# echo $PATH | Cut-d ': '-F 5
To: As a delimiter, so the/usr/local/bin will appear
-d ': ' To: As a delimiter
-F 5 Displays characters before the fifth delimiter

Tee command: At the same time the data flow to the file to go to the screen, and output 刡 screen, is actually stdout, can let the next command to continue processing
/db2home/asiainfo/wangbin/test Projser $ps | Tee./ps.txt | Head-1
Saves the results of the PS command to the Ps.txt file in the current directory and displays the first line of the result in standard output (screen).
-A saves the results to a file in Append mode

$touch a b c to create a, B, c three empty files at the same time
$rm a b c Delete both A, B, and C three empty files
$mkdir a b C to create three folders at a time
$rmdir a b C delete three folders at a time
$ls [xyz]* Find a file that starts with any of the letters in XYZ (including all file names in subdirectories with XYZ in the name)
$ls [!xyz]* Find Files not beginning with the letter xyz (including all file names in subdirectories containing XYZ in the name)
$ls *[xyz]* find files with any one letter of XYZ in the file name (including all file names in subdirectories containing XYZ in the name)

IP address (Note the format of the IP address must be:, the value of XXX must be a value of 0-255, and the first xxx is at least 1, the last xxx is at least 1.)
To verify the IP address of the regular expression:
'/^ ([1-9]| ([1-9]\d) | (1\d\d) | (2 ([0-4]\d|5[0-5]))) \.) ([1-9]| ([1-9]\d) | (1\d\d) | (2 ([0-4]\d|5[0-5]))) \.) {2} ([1-9]| ([1-9]\d) | (1\d\d) | (2 ([0-4]\d|5[0-5]))) $/'

Full awk Print Report Header/end of report usage: (Note: Do not forget the print in the end, there is no print in the document, error)
awk ' BEGIN {print ' 1\t2\t3\t4\t5\n----------} {print $ "\ t" $ "t" $ "\ T" $4 "\ T" $ "$" END {print "End-of-report"} ' DATA.F

This nohup can ridiculed you in the offline withdrawal system
Can also ridiculed work continue import line

!! ...!! The part is running in a sqlplus environment, exit Sqlplus, enter the shell environment
The results from the query to the connection pool are then redirected to the A.txt file

Rm-f/db2home/asiainfo/wangbin/test/a.txt >/dev/null 2>&1
Sqlplus Sdbass/[email protected] <<!! >/db2home/asiainfo/wangbin/test/a.txt
Select a.export_id
From Crmdata_export A;

#==== executes the procedure at 23:00 2009-03-17/bin/sync
[[email protected] ~]# at 23:00 2009-03-17

#==== after 5 minutes to execute/bin/sync
[[email protected] ~]# at now + 5 minutes

Application of Xargs:
such as: Grep-i "# # #" |awk ' {print $} '
Result: AA
Grep-i "# # #" |awk ' {print $} ' |xargs
Result: AA BB cc DD

GREP-E Applications:
Grep-i ABC *TCL search for ABC fields from a file with the suffix tcl
and, LS | Grep-e "Aa|bb|cc|dd" from the results of LS, searching for lines containing AA or BB or CC or DD, is a "or" application.

About viewing a directory or whether a file exists:
# # #目录是否存在-D parameter, presence returned 1
if [-d/db2home/asiainfo/wangbin/test]
echo exists test directory
else echo does not exist in the test directory
# # #文件是否存在-e parameter
echo exists file
else echo does not exist file

If [...]-a:and

Case usage in--shell
[/opt/dsadm/center/sh dw6]cat
#auto_city. Sh
#程序说明, the parameter is the file name, and returns the value of city_id (1-17,18 is not a city-to-market document)

Case $file _city in
echo 10;;
) echo 1;;
Echo 2;;
Echo 3;;
echo 4;;
) echo 5;;
) echo 6;;
echo 7;;
) echo 8;;
echo 9;;
one) echo 11;;
echo 12;;
echo 13;;
Echo 14;;
echo 15;;
(+) echo 16;;
(+) echo 17;;
*) echo 18;;

--There are spaces on both sides of the operator
/db2home/asiainfo projser $echo $a $b$c
/db2home/asiainfo projser $count = ' expr $a + $b + $c '
/db2home/asiainfo Projser $echo $count
/db2home/asiainfo projser $count = ' expr $a + $b + $c '
/db2home/asiainfo Projser $echo $count

--aix Setting the beist time zone
Determine if AIX is using daylight saving time: $echo $TZ Use this command to see the timezone, if the time zone ends with a dt using daylight savings, such as: CST6CDT
Set the time zone, under the/etc/environment file of the directory etc:
/etc dw1 $grep-I beist Environment
--Beijing time: East Eight District
tz= ' BEIST-8 '

tz= ' beist+16 '
/db2home/asiainfo Projser $date
February 23, 2012 Thursday 17:57 40 seconds
/db2home/asiainfo Projser $export tz=beist+16
/db2home/asiainfo Projser $date
February 22, 2012 Wednesday 17:57 45 seconds

# # # Tomorrow
Export tz=beist-32
/db2home/asiainfo Projser $export tz=beist-32
/db2home/asiainfo Projser $date
February 24, 2012 Friday 18:02 30 seconds

Some special initialization files are used to execute some shell configuration commands, with the dot number (.) Started, called point files. To show them, with Ls-a

CP/MV command, use parameter-I to avoid overwriting files when files are present

Using \ Masking The meaning of a special character, the following characters can be considered special characters:
$ . ' "* [] ^ | ( ) \ + ?
such as: the. Escape, \.
The above pattern does not consider the character behind the backslash to be a special character, but rather an ordinary character, that is, a period.
If you want to match all files ending with *.pas in a regular expression, do the following:/*/.pas

Cp-r Dir1 Dir2--Copies all files in the Dir1 directory to Dir2. -r parameter, recursive replication
Cp-i file1 Dir1--When you copy a file to Dir1, if you have this file in Dir1, ask

Mv-f file1 Dir1--forces the file to be moved to the directory, regardless of whether there is a file with the same name in the directory. -F: Mandatory. Force
Mv-i file1 Dir1-Ask when you have the same file. (with CP)

============================================= 2014/5/6 11:43:18 Nanchang Bank study record ========================================= ==
[Email protected]/home/db2inst1/wb>cat > #建立文件, using cat copy terminal input
Who|wc-l #程序内容
^d #ctrl +d says End-of-file
[Email protected]/home/db2inst1/wb>chmod +x Let the file have Execute permission
[Email protected]/home/db2inst1/wb> #执行测试
4 #测试结果

Description: Who, tell you who is currently logged in to the system

#!/usr/bin/ksh # #! specifies which Unix kernel shell to use

--3. Two commands can be separated by a semicolon

1. View Linux Memory: Vmstat
2. After executing the script with Nohup &, after prompting Nohup to succeed, you also need to press any key on the terminal to return to the Shell Input Command window, and then exit the terminal by entering exit in the shell.
And I am every time after the successful execution of the nohup directly click the Close Program button to close the terminal. So this time will be broken the corresponding session of the command, resulting in nohup corresponding process is notified need to shutdown together.

The Nohup command can be used to execute additional commands, and ignores the sighup signal (run a command immune to hangups, with output to a non-tty. Run COMMAND, ignoring hangup signals.)
When a virtual terminal's network connection is disconnected, the operating system sends a sighup signal (HUP = hangup, hangs) to the running program, which, by default, causes the program to exit.

3.linux down
3.1 Tar Basic usage:
TAR-CF All.tar *.jpg---all JPG files are made into a package named All.tar;-c to generate a new package;-F, specifying the package name
TAR-RF All.tar a.jpg--Adds the a.jpg file to the All.tar package. -R, add file.
Tar-uf All.tar logo.jpg--the logo.jpg file in the 1.tar package. -U, update file
TAR-TF All.tar--Lists all files in the package. -T, listing files
TAR-XF All.tar--All files in the All.tar package are solved. -X, Solution (unpacking *.tar)

3.2 Tar call gzip (-Z, call gzip)
TAR-CZF all.tar.gz *.jpg--to make all JPG files into a package called All.tar and compress them in gzip to generate a gzip compressed package all.tar.gz
Tar-xzf all.tar.gz--all.tar.gz unpack the above package (unzip the tarball *.tar.gz)

Note: No gzip is installed under AIX, so the z parameter is not available

Linux Learning Notes

Related Article

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: 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.