65.shell special symbols with and Cut,sort,wc,uniq,tee,tr,split commands

Source: Internet
Author: User

Special symbols for Liunx
    • Represents a number of letters or numbers
      ? Any one character
      "#" Comment
      \ de-Semantic characters
      | Pipe character
1.* represents any arbitrary character or number

[[email protected]/]# ls *.txt
1.txt
[Email protected]/]#

2.? Any one character

[email protected]/]# ls?. txt
1.txt
[Email protected]/]#

3. Notes

[Email protected]/]# #11111
[Email protected]/]#
PS: Meaning is the explanation

4, \ de-righteousness

[[email protected]/]# ls. txt
1.txt
[[email protected]/]# ls *.txt
LS: Cannot access
the. txt: no file or directory
[Email protected]/]#

5. Pipe break

[Email protected]/]# Cat/etc/passwd|grep root
Root:x:0:0:root:/root:/bin/bash
Operator:x:11:0:operator:/root:/sbin/nologin
[Email protected]/]#

Cut command Command type

File Management

Command description

Used to intercept a field to display it.

Command syntax

Cut "Parameters"

Parameters

-D,--delimiter= delimiter uses the specified delimiter instead of a tab as the area demarcation
-C, the--characters= list selects only those characters that are specified
-F: Specify a section

Case: View the/etc/passwd file to: Display the first paragraph for the separator

[[email protected]/]# cat/etc/passwd|head |cut-d ":"-F 1
Root
Bin
Daemon
cd/
Lp
Sync
Shutdown
Halt
Mail
operator
[Email protected]/]#

Sort Command Command description

This command is used to sort the document

Command syntax

sort [parameters] [file]

Parameters

-T separator: Same as cut-d
-N: Sorting with pure numbers
-R: Direction sort
-U: To repeat
-K:-kn1,n2: Sorted by N1 interval to N2 interval, can only write-kn1, sort N1 field

Case one: Without any parameters, the ASCII values are compared, and finally they are output in ascending order.

[Email protected]/]#
[Email protected]/]# Head/etc/passwd|sort
Adm:x:3:4:adm:/var/adm:/sbin/nologin
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Halt:x:7:0:halt:/sbin:/sbin/halt
Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
Operator:x:11:0:operator:/root:/sbin/nologin
Root:x:0:0:root:/root:/bin/bash
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
Sync:x:5:0:sync:/sbin:/bin/sync
[Email protected]/]#

WC Command Command description

For statistical

Command syntax

WC [parametric]

Parameters

-L: Count rows
-M: Statistics of characters
-W: Number of statistical words

Case

[Email protected]/]# cat/etc/passwd |wc-l-m-w
19 29 883
[Email protected]/]# cat/etc/passwd |WC
19 29 883
[Email protected]/]#

PS: In fact, there is no need to add parameters

UNIP Command Command description

Used to delete duplicate rows

Command syntax

Xxxxx|unip
Parameters
-C statistics Number of rows to repeat

Case

[Email protected] ~]# Uniq testb.txt
111
222
111
333
[Email protected] ~]# sort Testb.txt |uniq
111
222
333
[Email protected] ~]# sort Testb.txt |uniq-c
2 111
1 222
1 333

Tee command

Tee followed by the filename, its role is similar to redirect,, the specific gravity of a function, the file is written to the following file and displayed on the screen, usually used for pipe character |

Case

#echo "AAAAAAAAAAAAAAA" |tee testb.txt
Aaaaaaaaaaaaaaa
#cat Testb.txt
Aaaaaaaaaaaaaaa

Command TR

TR is used to replace characters, which are commonly used to handle special symbols appearing in documents, such as the symbol ^m that appear in a DOS document.
Options:

Parameters

-D means to delete a character followed by the character to be deleted.
-S means to remove duplicate characters.
Turn lowercase letters into uppercase letters, such as TR ' [A-z] ' [A-z] ':

Case

#head –n2/etc/passwd |tr ' [A-z] ' [A-z] '
Root:x:o:o:root:/root:/bin/bash
Bin:x:11:bin:/bin:/sbin/nologin
You can also replace one character:
#grep ' root '/etc/passwd |tr ' r ' R '
Root:x:o:o:root:/root:/bin/bash
Operator:x:11:0:operator:/root:/sbin/nologin

Command Split command description

Split is used for cutting documents, and the common options are-B and-L.

Parameters

-B means that the document is split by size in bytes
-L to divide the document by the number of rows

Case

#split –b passwd
#ls
passwd xaa xab xac xad xae

Shell some other special symbols 1, special symbols $

$ can be used as an identifier in front of a variable, and you can! Used in combination.

#cd:
#ls Testb.txt
Testb.txt
#ls!$
LS Testb.txt
Testb.txt
!$ represents the last variable of the previous command, and in this case the last command is Testb.txt, then entering!$ under the current command represents Testb.txt.

2, special symbols;

To run two or more two commands in a single line of commands, you need to add a symbol between the commands.

#mkdir Testb.txt; Touch Test1.txt; Touch Test2.txt; Ls–d test* Creating directories, creating files, listing directories

3. Special Symbols ~

The symbol ~ Represents the user's home directory, the root user's home directory is/root, the normal user's home directory is/home/username.

4. Special Symbols &

If you put a command in the background, you need to add the symbolic &, which is usually used for long commands. For example, it can be used after sleep, as shown below:

#sleep &
[1]3008
#jobs
[1]+ Running in Sleep &

5. REDIRECT Symbols >, >>, 2> and 2>>

and >> the meaning of substitution and append respectively. When we run a command error, the error message is output to the current screen. If you want to redirect to a text, use the redirect symbol 2> or 2>>, which represent error redirection and error append redirection, respectively.
#ls AAAA
LS: Unable to access AAAA: No file or directory
#ls AAAA 2>/tmp/error
#cat/tmp/error
LS: Unable to access AAAA: No file or directory
#ls AAAA 2>>/tmp/error
#cat/tmp/error
LS: Unable to access AAAA: No file or directory
LS: Unable to access AAAA: No file or directory

6. Brackets []

The combination of characters in brackets, representing any of the character combinations, can also represent a range (1-3,a-z).

#cd/TMP/10
#ls –d test*
Test1.txt test2.txt Testb.txt TestDir
#ls –d Test[1-3].txt
Test1.txt Test2.txt
#ls –d Test[12b].txt
Test1.txt Test2.txt Testb.txt
#ls –d Test[1-9].txt
Test1.txt Test2.txt
#ls –d Test[1-9a-z].txt
Test1.txt Test2.txt Testb.txt

7. Special Symbols && | |

A semicolon has just been mentioned above for the delimiter between multiple commands. There are also two special symbols that can be used in the middle of multiple commands, that is, "&&" and "| |" are all listed below:

Command1; Command2
Command1 && Command2
Command1 | | Command2
When using ";", Command2 will be executed regardless of whether Command1 is executed successfully;
When using "&&", only if the Command1 is executed successfully, Command2 will execute, otherwise command2 not execute;
When using "| |", the Command1 execution succeeds Command2 not execute, otherwise go to execute Command2, in short Command1 and Command2 always have a command to execute.

65.shell special symbols with and Cut,sort,wc,uniq,tee,tr,split commands

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.