Shell special Characters

Source: Internet
Author: User
Tags create directory

Special symbols

    • Wildcard characters, any character
      ? Any of the characters
      . #注释字符
      \ de-Semantic characters
      | Pipeline

Several commands related to pipelines
Cut select information for the row analysis
Main parameters
-B: Split in bytes. These byte locations will ignore multibyte character boundaries unless the-n flag is also specified.
-C: Split in characters.
-D: Custom delimiter, default is tab.
-F: Used with-D to specify which area to display.
-N: Cancels splitting multibyte characters. Used only with the-B flag. If the last byte of the character falls within the range of <br/> indicated by the List parameter of the-B flag, the character will be written out; otherwise, the character will be excluded.

Sort sorted by default in ASC code

[[email protected] ~]# sort/etc/passwd
Adm:x:3:4:adm:/var/adm:/sbin/nologin
Avahi-autoipd:x : 170:170:avahi ipv4ll stack:/var/lib/avahi-autoipd:/sbin/nologin
Avahi:x:70:70:avahi MDNS/DNS-SD Stack:/var/run /avahi-daemon:/sbin/nologin
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Dbus:x:81:81:system message bus:/:/sbin/nologin
ftp:x:14:50:ftp user:/var/ftp:/sbin/nologin
games:x:12:100: Games:/usr/games:/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
Nobody:x:99:99:nobody:/:/sbin/nologin
operator:x:11:0 : Operator:/root:/sbin/nologin
Polkitd:x:999:998:user for Polkitd:/:/sbin/nologin
postfix:x:89:89::/var/ Spool/postfix:/sbin/nologin
Root:x:0:0:root:/root:/bin/bash
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sshd:x:74:74:privilege-separated ssh:/var/empty/sshd:/sbin/nologin
Sync:x:5:0:sync:/sbin:/bin/sync

SORT-R Reverse

WC statistics

-l statistic number of rows-m statistic characters-W statistics
[Email protected] ~]# wc-l 1.txt
1.txt
[Email protected] ~]# wc-m 1.txt
468 1.txt
[Email protected] ~]# wc-w 1.txt
1.txt

Uniq sort-C to go heavy
[Email protected] ~]# sort 2.txt
1
1
1
123
123
2
2
2
21st
21st
21st
21st
21st
21st
21st
21st
21st
21st
21st
21st
21st
21st
21st
21st
21st
21st
21st
21st
21st
3
Abc
ABC 1111,222
[Email protected] ~]# Sort 2.txt | Uniq
1
123
2
21st
3
Abc
ABC 1111,222

[Email protected] ~]# Sort 2.txt | Uniq-c
3 1
2 123
3 2
21 21
1 3
1 ABC
1 ABC 1111,222

Tee and > output redirection are similar

[Email protected] ~]# >a.txt #清空a. txt content
[email protected] ~]# cat a.txt #查看
[Email protected] ~]# Sort 2.txt | uniq-c | Tee A.txt #重定向并显示
3 1
2 123
3 2
21 21
1 3
1 ABC
1 ABC 1111,222
[email protected] ~]# cat A.txt
3 1
2 123
3 2
21 21
1 3
1 ABC
1 ABC 1111,222

[Email protected] ~]# Sort 2.txt | uniq-c | Tee-a a.txt #追加
3 1
2 123
3 2
21 21
1 3
1 ABC
1 ABC 1111,222
[email protected] ~]# cat a.txt #查看内容
2 123
3 2
21 21
1 3
1 ABC
1 ABC 1111,222
3 1
2 123
3 2
21 21
1 3
1 ABC
1 ABC 1111,222

TR Replacement Character

[Email protected] ~]# echo "Aminglinux" |tr ' [al] ' [Al] '
Aminglinux
[[email protected] ~]# echo "Aminglinux" |tr ' a ' a '
Aminglinux

Split cut

[Email protected] test]# split-b 100k a.txt
[[email protected] test]# ls
A.txt Xaa Xab
[Email protected] test]# Du-sh
128K A.txt
100K XAA
28K Xab
[Email protected] test]# split-b 100k a.txt ABC. #指定大小
[[email protected] test]# ls
Abc.aa Abc.ab A.txt
[Email protected] test]# split-l a.txt #指定行
[Email protected] test]# ls-l
Total Dosage 260
-rw-r--r--. 1 root root 129633 January 07:31 a.txt
-rw-r--r--. 1 root root 41537 January 07:32 Xaa
-rw-r--r--. 1 root root 35466 January 07:32 xab
-rw-r--r--. 1 root root 36841 January 07:32 xac
-rw-r--r--. 1 root root 15789 January 07:32 xad
[Email protected] test]# wc-l

3549 A.txt
Xaa
Xab
Xac
549 Xad
7098 Total Dosage

Special symbols

$ variable Prefix
! $ combination, regular inside means end of line
Multiple lines of command write to one line, use; split
~ User home directory, regular expression indicates match
& After the command is placed, the command hangs in the background

>> 2> 2>> &>
[] One of the specified characters, [0-9][a-z][a-z]

|| and && for the logical relationship between commands

[[email protected] ~]# ls 1.txt; wc-l 2.txt
1.txt
2.txt
[[email protected] ~]# ls 1.txt | | Wc-l 2.txt
1.txt
The current polygon command succeeds and does not execute subsequent commands
[[email protected] ~]# ls 1.txt && wc-l 2.txt
1.txt
2.txt
[[email protected] ~]# ls 1a.txt && wc-l 2.txt
LS: Unable to access 1a.txt: No file or directory
When the preceding command is unsuccessful, the following command is not executed

[[Email protected] ~]# [-D aminglinux] | | mkdir Aminglinux
If the Aminglinux directory does not exist, create the Aminglinux directory
[-D n] Fixed format
[[email protected] ~]# ls
1.txt 2.txt 3.txt aaaa.txt aminglinux anaconda-ks.cfg a.txt; : Q Test

[[Email protected] ~]# [-D aminglinux] && mkdir aminglinux
mkdir: Unable to create directory "Aminglinux": File already exists
[[Email protected] ~]# [-D aminglinux] | | mkdir Aminglinux

Shell special Characters

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.