Shell theory Learning (II.)

Source: Internet
Author: User
Tags diff

30.tee: Reads the standard input and then displays it by the standard output and stores the data in the specified file

Execute this command, test.txt if it already exists, it will be emptied, if it does not exist a new file will be created, end the operation Ctrl+d

[Email protected] ~]# Tee Test.txthello my World!hello my world! [email protected] ~]# cat test.txt Hello my world!

-A is appended to the file, the input data is connected to the end of the Test.txt file, and the test.txt is not emptied.

[Email protected] ~]# tee-a test.txt This is a zhuijia! This is a zhuijia! [email protected] ~]# cat test.txt Hello my world! This is a zhuijia!

31.diff: Compare differences of two files

[Email protected] test]# diff file4.txt ... /test.txt 1,2c1,2< haha< Hello myworld---> Hello my world!> this is a zhuijia!

32.xargs: Set the command and parameters to be executed by standard input

Looking for a. txt file, and then to Xargs processing,-N 2 for the command to execute the parameters of up to two, that is to say: Find the. txt file, two a group of ways to diff to compare

[Email protected] ~]# find/root/test/-name "*.txt" | Xargs-n 2 diff1,2d0< haha< Hello MyWorld

33. Multiple commands can be made into a group, then the whole group to execute

Method One: (command 1; command 2; command 3)

() opens a child shell environment to execute the command group in parentheses

[[Email protected] ~]# (cat test.txt;find/root/test/-name "*.txt";d ate +%f) Hello my world! This is a zhuijia!/root/test/file5.txt/root/test/file2.txt/root/test/file4.txt/root/test/file3.txt2015-01-09

Method Two: {command 1; command 2; command 3;}

In contrast to the first method, this is the way the command group executes in the current shell, not in the child shell.

[email protected] ~]# {cat test.txt;find/root/test/-name "*.txt";d ate +%f;} Hello my world! This is a zhuijia!/root/test/file5.txt/root/test/file2.txt/root/test/file4.txt/root/test/file3.txt2015-01-09

34. Record command Execution process

Sometimes, we need to record the information generated by the execution of the order as a troubleshooting reference, for data preservation purposes.

script[log file]

If you do not provide a custom log file, the default is to store the data in the Typescript file

After executing the script command, you can start to manipulate various commands, and script will faithfully record all output information. If you want to end the operation, exit script

[Email protected] ~]# script /tmp/test.txtscript started, file is /tmp /test.txt[[email protected] ~]# ls /tmp/test.txt /tmp/test.txt[[email protected]  ~]# { cat test.txt;find /root/test/ -name  "*.txt";d ate +%f; } hello my world! this is a zhuijia!/root/test/file5.txt/root/test/file2.txt/root/test/file4.txt/root/test/ file3.txt2015-01-09[[email protected] ~]# find /root/test/ -name  "*.txt"    | xargs -n 2 diff1,2d0< haha< hello myworld[[email  protected] ~]# exitexitscript done, file is /tmp/test.txt# View Log [email  protected] ~]# head /tmp/test.txt script started on 2015 January 09   Friday  17 53 minutes 07 seconds [[Email protected] ~]# { cat test.txt;find /root/test/ -name   "*.txt";d ate +%f; }hello my world! this is a zhuijia!/root/test/file5.txt/root/test/file2.txt/root/test/file4.txt/root/test/ file3.txt2015-01-09[[email protected] ~]# find /root/test/ -name  "*.txt"    | xargs -n 2 diff

35.unset:

UNSET-V variable Name

Option-V indicates that a variable is to be canceled

unset-f function name

Option-f means that the function is to be canceled

36. Common environment variables

    • PS1: Main prompt

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/5A/wKioL1TQ7F7yQ8X_AALsRCZXE58668.jpg "title=" 1.PNG " alt= "Wkiol1tq7f7yq8x_aalsrczxe58668.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/5A/wKioL1TQ7PyxOoaeAAByTckp-Sk008.jpg "title=" 2.PNG " alt= "Wkiol1tq7pyxooaeaabytckp-sk008.jpg"/>

This article is from the "Linux Revolution" blog, so be sure to keep this source http://kaibinyuan.blog.51cto.com/7304008/1611304

Shell theory Learning (II.)

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