Linux Learning |, >, | | Symbol

Source: Internet
Author: User


Sequential combination command:

1. Sequential execution of commands, no sign of judgment between commands;

For example: sync;sync;shutdown-h now-----continuously synchronize the disk and then shut down, regardless of whether the previous command was executed successfully

2. Execute the correlation command consecutively before continuing with the next connector after successful execution of the previous command &&

For example: LS/TMP/ABC && touch/tmp/abc/test.txt---If the directory does not exist then no files will be created later

3. Continuous command Previous command execution failed continue execution Connector | |

Example: LS/TMP/ABC | | Mkdir/tmp/abc

The above commands can be combined using: Ls/tmp/test && echo "Exist" | | echo "no exist"

Example: LS/TMP/ABC | | MKDIR/TMP/ABC && Touch/tmp/abc/test.txt

Free combination of commands for different functions


Data Flow redirection:

1. Save the correct output and error information to a separate file.

find/home/-name. BASHRC >/tmp/abc/list_right 2>/tmp/abc/list_error

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/91/56/wKioL1j1g0mi3Rz4AAA9vsTbgGk141.png-wh_500x0-wm_ 3-wmp_4-s_295018672.png "title=" Qq20170418110818.png "alt=" Wkiol1j1g0mi3rz4aaa9vstbggk141.png-wh_50 "/>


2. The resulting error message is ignored or stored, and the output can be redirected to the/dev/null black hole device.

Find/home-name. BASHRC 2>/dev/null

In fact, mostly used in some large but no useful information on the output. In daily work, it is possible to filter out some of the successful information from the output information to redirect to the specified file for easy query troubleshooting, or for next steps


3. Write the correct or error information of the output to a file, with the following two sentences executing the same result.

Find/home-name. BASHRC >/tmp/abc/list 2>&1

Find/home-name. BASHRC &>/tmp/abc/list

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/91/59/wKiom1j1h_uSFYSxAAAgLKwJqwE121.png-wh_500x0-wm_ 3-wmp_4-s_3816969842.png "title=" Qq20170418112836.png "alt=" Wkiom1j1h_usfysxaaaglkwjqwe121.png-wh_50 "/>


4. Redirect content from the specified text to a new file

The cat >list_error <test.txt is the copy of the content in the Test.txt to List_error < will overwrite the original content


The application of pipeline commands is combined with:

1. Correct output in order Processing standard

ls-al/etc/| Less output face screen continuous display


2. Show by: Split the 2nd foot character cut

echo $PATH | Cut-d ': '-F 2 equals echo $PATH | Awk-f: ' {print $} '

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/91/58/wKioL1j1i1TgAMkzAAAZC2vO-ZU402.png-wh_500x0-wm_ 3-wmp_4-s_595210952.png "title=" Qq20170418114252.png "alt=" Wkiol1j1i1tgamkzaaazc2vo-zu402.png-wh_50 "/>


3. Cut out all characters after export of 12 column characters

Export | Cut-c 12-

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/91/59/wKioL1j1jQSwDnFQAAAm3Pu-wmw379.png-wh_500x0-wm_ 3-wmp_4-s_2494998832.png "title=" Qq20170418115004.png "alt=" Wkiol1j1jqswdnfqaaam3pu-wmw379.png-wh_50 "/>

Export | Cut-c 12-16 Displays only 12-16 columns of content, which is 5 characters per line.

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/91/5A/wKiom1j1jRPzFYrfAAAN_eHO-mE014.png-wh_500x0-wm_ 3-wmp_4-s_4002482328.png "title=" Qq20170418114945.png "alt=" Wkiom1j1jrpzfyrfaaan_eho-me014.png-wh_50 "/>

Compare the output to know what's going on, right?


4. Display all users who have previously logged in , cut, grep

Last | Cut-d '-f1 here-D is a custom delimiter,-F1 shows the first column


5. Display non-root login user

Last | Grep-v ' Root '

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/91/59/wKioL1j1k0nzS5QrAABE_OuUijU131.png-wh_500x0-wm_ 3-wmp_4-s_3090878499.png "title=" Qq20170418121652.png "alt=" Wkiol1j1k0nzs5qraabe_ouuiju131.png-wh_50 "/>


6. Remove the Manpath from the man.config to color grep

grep--color=auto ' MANPATH '/etc/man.config

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/91/5B/wKiom1j1k6-SE6cZAAAy6QMHd4M080.png-wh_500x0-wm_ 3-wmp_4-s_3090318304.png "title=" Qq20170418121832.png "alt=" Wkiom1j1k6-se6czaaay6qmhd4m080.png-wh_50 "/>


7. Sort the user accounts under the system

cat/etc/passwd | Sort-------Default by first letter

cat/etc/passwd | Sort-t ': '-K 3---------------sorted by: Third column separated by symbols

cat/etc/passwd | Sort-t ': '-K 3-n------------sorted by the number of the third column separated by: symbol

cat/etc/passwd | Sort-t ': '-K 3-n | Cut-d ': '-F3 show third column

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/91/5A/wKioL1j1lPugQhwPAAAPErm0Lqs271.png-wh_500x0-wm_ 3-wmp_4-s_2188906593.png "title=" Qq20170418122405.png "alt=" Wkiol1j1lpugqhwpaaaperm0lqs271.png-wh_50 "/>


8. List all user names that have logged in to this system

Last | Cut-d '-f1 | Sort

Last | Cut-d '-f1 | Sort | Uniq----------Non-repeating list Uniq

Last | Cut-d '-f1 | Sort | Uniq-c--------Non-recurring list and Count

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/91/5B/wKiom1j1lYrhrsykAAAQIPd8kZI874.png-wh_500x0-wm_ 3-wmp_4-s_1127642507.png "title=" Qq20170418122629.png "alt=" Wkiom1j1lyrhrsykaaaqipd8kzi874.png-wh_50 "/>

Last | Cut-d '-f1 | Sort | uniq-c | Sed ' s/^/& stats:/g '-----That's more intuitive.

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/91/5B/wKiom1j1lmuDFe-aAAAdMNQEfZQ869.png-wh_500x0-wm_ 3-wmp_4-s_301728359.png "title=" Qq20170418123016.png "alt=" Wkiom1j1lmudfe-aaaadmnqefzq869.png-wh_50 "/>

Note: There is a space in the middle of the symbol, otherwise it will be an error.


9. Count the number of lines, words, and characters in the document WC

Cat/etc/man.config | Wc

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/91/5C/wKiom1j1mECybz66AAARnIPLpn4712.png-wh_500x0-wm_ 3-wmp_4-s_1374356435.png "title=" Qq20170418123806.png "alt=" Wkiom1j1mecybz66aaarniplpn4712.png-wh_50 "/>

Last | grep [A-za-z] | Grep-v ' wtmp ' | Wc-l count the total number of logged-in systems count the rows taken out of non-blank rows and excluded Wtmp


10. Save the output to the Last.list tee

Last | Tee Last.list | Cut-d '-F1-----The first column after the output is saved to the document


11. Save a copy to the file and display it on the screen

Ls-l/home/| Tee/tmp/homefile | More

Ls-l/etc/| Tee-a/tmp/etcfile | The more-a parameter allows the output to be appended to the file instead of overwriting the file contents


12. Replace all lowercase letters in the output with uppercase TR

Last | TR ' [A-z] ' [A-z] '---can be used to solve the document content normalization problem, facilitate post-processing

cat/etc/passwd | Tr-d ': '-----------Delete the: number in the document

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/91/5E/wKiom1j1qSeCHpLoAAAhtbpV0O4066.png-wh_500x0-wm_ 3-wmp_4-s_1587701018.png "title=" Qq20170418134958.png "alt=" Wkiom1j1qsechploaaahtbpv0o4066.png-wh_50 "/>

Cat-a/etc/passwd

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/91/5D/wKioL1j1qKfzFWltAAA2cilSuZU578.png-wh_500x0-wm_ 3-wmp_4-s_3295691950.png "title=" Qq20170418134746.png "alt=" Wkiol1j1qkfzfwltaaa2cilsuzu578.png-wh_50 "/>

CP/ETC/PASSWD/ROOT/PASSWD && unix2dos /root/passwd---Copy text and save with DOS

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/91/5D/wKioL1j1qM6hxKs6AAA-ERZSjDw391.png-wh_500x0-wm_ 3-wmp_4-s_201101174.png "title=" Qq20170418134844.png "alt=" Wkiol1j1qm6hxks6aaa-erzsjdw391.png-wh_50 "/>

cat/root/passwd | Tr-d ' \ r ' >/root/passwd.linux---Remove the break from the converted text and save


FILE/ETC/PASSWD/ROOT/PASSWD Comparison of two document formats


13. Display special keys in the document

Cat-a/etc/man.config---Show special characters $^ in the document, etc.

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/91/5D/wKioL1j1qmfxPtgMAABBVS_Iv6M863.png-wh_500x0-wm_ 3-wmp_4-s_1076470069.png "title=" Qq20170418135527.png "alt=" Wkiol1j1qmfxptgmaabbvs_iv6m863.png-wh_50 "/>

Cat/etc/man.config | Col-x | cat-a | More----------Replace the original [tab] key with a space

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/91/5D/wKioL1j1qpPxVE5GAAAzRPiajYg414.png-wh_500x0-wm_ 3-wmp_4-s_3937923321.png "title=" Qq20170418135610.png "alt=" Wkiol1j1qppxve5gaaazrpiajyg414.png-wh_50 "/>

Tail-n 20/etc/man.config | Col-x | cat-a | Tr-d ' $ '--you can also remove the trailing $ sign


14. Merge files with the same part into the join

Join-t ': '/etc/passwd/etc/shadow-----Connect the same two documents in the first field

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/91/5F/wKioL1j1sh-CSkgUAABHedkjbI0545.png-wh_500x0-wm_ 3-wmp_4-s_2306327835.png "title=" Qq20170418142826.png "alt=" Wkiol1j1sh-cskguaabhedkjbi0545.png-wh_50 "/>

Join-t ': '-1 4/etc/passwd-2 3/etc/group---Connect the 4th field of the first document to the 3rd field of the second document


15. Connect the two lines in the file together paste

Paste/etc/passwd/etc/shadow--combined to show it together

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/91/60/wKiom1j1smKzQ1-sAABLMGAVSe4729.png-wh_500x0-wm_ 3-wmp_4-s_1194152249.png "title=" Qq20170418142935.png "alt=" Wkiom1j1smkzq1-saablmgavse4729.png-wh_50 "/>

Cat/etc/group | Paste/etc/passwd/etc/shadow-| Head-n 3----Take only the first 3 rows of the output


16. The [tab] key in the document, displayed as ^i with Cat-a

grep ' ^manpath '/etc/man.config | Head-n 3 | Cat-a

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/91/5F/wKioL1j1s5XBvqrlAAAecrM0Rdc311.png-wh_500x0-wm_ 3-wmp_4-s_2397113319.png "title=" Qq20170418143442.png "alt=" Wkiol1j1s5xbvqrlaaaecrm0rdc311.png-wh_50 "/>

grep ' ^manpath '/etc/man.config | Head-n 3 | Expand-t 6-| Cat-a change the above ^i to 6 spaces

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/91/5F/wKioL1j1s-PR-y4QAAAe99G3_HI109.png-wh_500x0-wm_ 3-wmp_4-s_1758623939.png "title=" Qq20170418143559.png "alt=" Wkiol1j1s-pr-y4qaaae99g3_hi109.png-wh_50 "/>


17. Go to/tmp/file, cut the file into 30K, name termcap automatically add split

Cd/tmp/;split-b 30k Btts_14_to.zip Btts_14_to.zip

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/91/61/wKiom1j1tRSTjmtcAABWJruFry4046.png-wh_500x0-wm_ 3-wmp_4-s_2682757728.png "title=" Qq20170418144055.png "alt=" Wkiom1j1trstjmtcaabwjrufry4046.png-wh_50 "/>

Cat termcap* >>termcapback------------------------combine multiple documents into one file



This article is from the "Sed for linux commands" blog, so be sure to keep this source http://beforce.blog.51cto.com/3335637/1917016

Linux Learning |, >, | | Symbol

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.