shell特殊符号,wc,uniq,tee_tr_split命令

简介:

[root@abinlinux ~]# cut -d: -f 3 /etc/passwd   -d:分隔符    -f 加数字第几段     f是第几段

0

1

2

[root@abinlinux ~]# cut -d: -f 3,4,5,6,7 /etc/passwd  可以多选几段加,号就可以

0:0:root:/root:/bin/bash

1:1:bin:/bin:/sbin/nologin

2:2:daemon:/sbin:/sbin/nologin

3:4:adm:/var/adm:/sbin/nologin

[root@abinlinux ~]# cut -c 10 /etc/passwd    -c是第几个字符    c10就是第十个字符

0

:

2

[root@abinlinux ~]# cut -c 1-10 /etc/passwd    第一个到第十个  字符  -c是区间第几个

root:x:0:0

bin:x:1:1:

daemon:x:2



[root@abinlinux ~]# sort /etc/passwd    默认排序  阿斯玛排序

adm:x:3:4:adm:/var/adm:/sbin/nologin

apache:x:48:48:Apache:/var/www:/sbin/nologin

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

[root@abinlinux ~]# sort -t: -k3 /etc/passwd     -t:是分隔符  -k3 是第三段  排序

root:x:0:0:root:/root:/bin/bash

uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

operator:x:11:0:operator:/root:/sbin/nologin

bin:x:1:1:bin:/bin:/sbin/nologin

[root@abinlinux ~]# sort -t: -k3 -n /etc/passwd   -n 按数字排序   也可以-k 3,6  区间值

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

adm:x:3:4:adm:/var/adm:/sbin/nologin

[root@abinlinux ~]# sort -t: -k3,5 -n -r /etc/passwd      -r 是反序

yun:x:500:500::/home/yun:/bin/bash

saslauth:x:499:76:Saslauthd user:/var/empty/saslauth

bin:x:1:1:bin:/bin:/sbin/nologin

root:x:0:0:root:/root:/bin/bash

[root@abinlinux ~]# sort -t: -k 3,5 -n -r -u /etc/passwd   -u是去重复的 意思

sort -un 2.txt       也可以这样用


[root@abinlinux ~]# uniq -c 2.txt       加选项 -c 列出重复

1 1

1 2

1 3

2 4

1 5

2 6

1 7

2 8

2 9

[root@abinlinux ~]# sort 2.txt |uniq -c   排下序在去去重复

1 1

1 10

1 12

1 1212

1 12166

1 2

1 3

2 4

1 5

2 6

1 7

2 8

2 9

[root@abinlinux ~]# echo "1111111"  |tee 1.txt   tee的用法

1111111

[root@abinlinux ~]# echo "1111111"  |tee 1.txt

1111111

[root@abinlinux ~]# cat 1.txt

1111111


[root@abinlinux ~]# ls *.txt |tr 'a-z' 'A-Z'    .txt变成大写 字母名字变成大写  tr替换字符

1.TXT

2.TXT

C.TXT

M.TXT

Z.TXT

[root@abinlinux ~]# echo $ "jksadhasjkdh" |tr 'j' 'E'     替换大小写 字符

$ EksadhasEkdh

[root@abinlinux ~]# echo "jksadhasjkdh" |tr 'j' 'E'

EksadhasEkdh

[root@abinlinux ~]# echo "jksadhasjkdh" |tr 'a-z' 'A-Z'  全局替换     也可以范围缩小 ‘a-f’

JKSADHASJKDH

split  切割日志的

[root@abinlinux ~]# split -l 10 anaconda-ks.cfg      -l分多少行

[root@abinlinux ~]# ls

12               c.txt                   link     xaa   xab  

12.tar           install.log             m.txt    xac  

1.txt            install.log.syslog      wps     xad

[root@abinlinux ~]# du -sb anaconda-ks.cfg    查看大小

1028    anaconda-ks.cfg

[root@abinlinux ~]# split -b 100 anaconda-ks.cfg        -b 以100b切割

[root@abinlinux ~]# ls -lh xa*

-rw-r--r-- 1 root root 100 10月 27 07:53 xaa

-rw-r--r-- 1 root root 100 10月 27 07:53 xab

-rw-r--r-- 1 root root 100 10月 27 07:53 xac

-rw-r--r-- 1 root root 100 10月 27 07:53 xad

-rw-r--r-- 1 root root 100 10月 27 07:53 xae

-rw-r--r-- 1 root root 100 10月 27 07:53 xaf

-rw-r--r-- 1 root root 100 10月 27 07:53 xag

-rw-r--r-- 1 root root 100 10月 27 07:53 xah

-rw-r--r-- 1 root root 100 10月 27 07:53 xai

-rw-r--r-- 1 root root 100 10月 27 07:53 xaj

-rw-r--r-- 1 root root  28 10月 27 07:53 xak

[root@abinlinux ~]# split -b 100 anaconda-ks.cfg  new_      更改名字  new

[root@abinlinux ~]# ls

12                      link    new_ai   xaf

12.tar                  m.txt   new_aj   xag

1.txt                   new_aa  new_ak   xah

2.txt                   new_ab  wps      xai

anaconda-ks.cfg         new_ac  wps.zip  xaj


&&  并且  ||或者

[root@abinlinux ~]# ls 1.txt && ls 2.txt         能够执行第一个才会执行第二个

1.txt

2.txt

[root@abinlinux ~]# ls 1.txt && ls 20.txt     前面的命令执行成功才会执行后面的命令

1.txt

ls: 无法访问20.txt: 没有那个文件或目录

[root@abinlinux ~]# ls 10.txt && ls 2.txt    如果前面的命令没有执行成功 它不再执行后面的命令

ls: 无法访问10.txt: 没有那个文件或目录

[root@abinlinux ~]# ls 1.txt || ls 2.txt

1.txt

[root@abinlinux ~]# ls 10.txt || ls 20.txt

ls: 无法访问10.txt: 没有那个文件或目录

ls: 无法访问20.txt: 没有那个文件或目录

[root@abinlinux ~]# ls 10.txt || ls 2.txt

ls: 无法访问10.txt: 没有那个文件或目录

2.txt

&& 左边的命令执行成功后,才会执行右边的命令

||左边的命令执行不成功,才会执行右边的命令

;   左边的命令成功与否,后面命令都会执行




本文转自 amenging 51CTO博客,原文链接:http://blog.51cto.com/11335852/1982959
相关文章
|
6天前
|
Shell 程序员 数据安全/隐私保护
shell 脚本 if-else判断 和流程控制 (基本语法|基础命令)
shell 脚本 if-else判断 和流程控制 (基本语法|基础命令)
|
17天前
|
网络协议 Unix Shell
第十一章 Shell常用命令与工具(二)
第十一章 Shell常用命令与工具(二)
|
17天前
|
移动开发 Shell Linux
第十一章 Shell常用命令与工具(一)
第十一章 Shell常用命令与工具(一)
|
22天前
|
存储 Shell 数据安全/隐私保护
ZooKeeper【基础知识 04】控制权限ACL(原生的 Shell 命令)
【4月更文挑战第11天】ZooKeeper【基础知识 04】控制权限ACL(原生的 Shell 命令)
27 7
|
23天前
|
Shell
ZooKeeper【基础 02】zookeeper-3.6.0 常用Shell命令(节点增删改查+监听器+四字指令)
【4月更文挑战第10天】ZooKeeper【基础 02】zookeeper-3.6.0 常用Shell命令(节点增删改查+监听器+四字指令)
25 0
|
29天前
|
分布式计算 Hadoop Shell
Hadoop【基础知识 04】【HDFS常用shell命令】(hadoop fs + hadoop dfs + hdfs dfs 使用举例)
【4月更文挑战第4天】Hadoop【基础知识 04】【HDFS常用shell命令】(hadoop fs + hadoop dfs + hdfs dfs 使用举例)
33 5
|
1月前
|
Shell Linux
在linux shell脚本中root切换到普通用户执行脚本或命令的方法
在linux shell脚本中root切换到普通用户执行脚本或命令的方法
13 1
|
2天前
|
分布式计算 Hadoop Shell
使用shell脚本实现自动SSH互信功能
使用shell脚本实现自动SSH互信功能
10 1
|
2天前
|
Unix Shell Linux
轻松编写 AIX Shell 脚本
轻松编写 AIX Shell 脚本
11 1
|
3天前
|
监控 关系型数据库 Shell
Shell脚本入门:从基础到实践,轻松掌握Shell编程
Shell脚本入门:从基础到实践,轻松掌握Shell编程