查看系统变量:

1.env命令

[root@localhost ~]# env

2.set命令

[root@localhost ~]# set

*set可以显示用户自定义的变量

自定义变量:

1.定义变量:

[root@localhost ~]# a=test

[root@localhost ~]# echo $a

test

2.变量命名规则:可包含大小写字母、数字、下划线(不能以数字开头)

[root@localhost ~]# a=1

[root@localhost ~]# echo $a

1

[root@localhost ~]# a_1=2

[root@localhost ~]# echo $a_1

2

[root@localhost ~]# a1=3

[root@localhost ~]# echo $a1

3

[root@localhost ~]# 1a=4

-bash: 1a=4: 未找到命令

3.变量值含特殊字符($ / \ # 空格等等)时需添加单引号:

[root@localhost ~]# a=abc

[root@localhost ~]# echo $a

abc

[root@localhost ~]# a='a b c'

[root@localhost ~]# echo $a

a b c

[root@localhost ~]# a=a b c

-bash: b: 未找到命令

4.变量的累加:当变量值中包含变量名时需使用双引号才能读取变量的值,使用单引号变量名会被识别为字符串

[root@localhost ~]# a=1

[root@localhost ~]# b=2

[root@localhost ~]# echo $a$b

12

[root@localhost ~]# c='$a$b'

[root@localhost ~]# echo $c

$a$b

[root@localhost ~]# c="$a$b"

[root@localhost ~]# echo $c

12

5.全局变量:在当前的shell中(终端)定义的变量只在当前的shell中(终端)生效,使用全局变量可以使变量在当前shell的子shell中也生效,但在子shell中定义的全局变量不会再父shell中生效(全局变量只能在当前shell和当前shell的子shell中生效)

定义全局变量命令:export

[root@localhost ~]# a=test

[root@localhost ~]# echo $a

test

[root@localhost ~]# bash

[root@localhost ~]# echo $a

[root@localhost ~]# exit

exit

[root@localhost ~]# export a=test

[root@localhost ~]# bash

[root@localhost ~]# echo $a

test

6.删除变量:unset 变量名

[root@localhost ~]# a=1

[root@localhost ~]# echo $a

1

[root@localhost ~]# unset a

环境变量:

1.变量配置文件:

a.系统层面:/etc/profile、/etc/bashrc

b.用户层面:~/.bash_profile、\~/.bashrc、\~/.bash_history、\~/.bash_logout

*系统层面的配置文件通常在登录时加载,用户层面的配置文件只对单个用户生效

2.PS1变量:表示每行命令行最前端的内容([root@localhost ~]#)

[root@localhost ~]# echo $PS1

[\u@\h \W]\$

*u代表用户,h代表hostname,W代表当前所在目录

将大写W改为小写w后显示绝对路径:

[root@localhost ~]#cd /etc/sysconfig/

[root@localhost sysconfig]#PS1='[\u@\h \w]\$'

[root@localhost /etc/sysconfig]#

3.PS2变量:(在另一种模式中使用,比如登录mysql后)

[root@localhost ~]#echo $PS2

>

cut分割命令:

-d 参数:指定分割符号,-f 参数:指定段数,-c 参数:指定第几个字符

[root@localhost ~]#cat 1.txt

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

[root@localhost ~]#cat 1.txt |cut -d ":" -f 1

root

[root@localhost ~]#cat 1.txt |cut -d ":" -f 1,2

root:x

[root@localhost ~]#cat 1.txt |cut -d ":" -f 1-5

root:x:0:0:root

[root@localhost ~]#cat 1.txt |cut -c 4

t

sort排序命令:将每行的内容以ASCII码从小到大排序

[root@localhost ~]#

[root@localhost ~]#cat 1.txt

abc

aa_1

a

abbop

#test

404

2018

5

[root@localhost ~]#sort 1.txt

2018

404

5

a

aa_1

abbop

abc

#test

-n 参数:以数字从小到大排序(字母和特殊符号开头的行会被默认为0)

[root@localhost ~]#cat 1.txt

abc

aa_1

a

abbop

#test

404

2018

5

[root@localhost ~]#sort -n 1.txt

a

aa_1

abbop

abc

#test

5

404

2018

-r 参数:倒序排序

[root@localhost ~]#sort -n 1.txt

a

aa_1

abbop

abc

#test

5

404

2018

[root@localhost ~]#sort -nr 1.txt

2018

404

5

#test

abc

abbop

aa_1

a

wc统计命令:

-l 参数:统计行数

[root@localhost ~]#cat test.txt

abc

aa_1

a

abbop

#test

404

2018

5

[root@localhost ~]#wc -l test.txt

9 test.txt

-m 参数:统计字符数

[root@localhost ~]#cat a.txt

2019

0917

[root@localhost ~]#wc -m a.txt

10 a.txt

*cat查看文件内容显示只有8个字符,但wc -m显示10个字符是因为还有隐藏换行符 "$"

[root@localhost ~]#cat -A a.txt

2019$

0917$

-w 参数:统计词数(以空格分隔)

[root@localhost ~]#cat a.txt

2019

0917 hello,world test

[root@localhost ~]#wc -w a.txt

4 a.txt

uniq去重命令:

uniq只能在相邻的行之间去重,所以uniq一般配合sort使用,先排序再去重:

[root@localhost ~]#cat a.txt

2019

hello world

test

test

1

1

2019

[root@localhost ~]#uniq a.txt

2019

hello world

test

1

2019 #该行未被去重

结合sort排序命令使用:

[root@localhost ~]#cat a.txt

2019

hello world

test

test

1

1

2019

[root@localhost ~]#sort a.txt | uniq

1

2019

hello world

test

-c 参数:统计去重次数

[root@localhost ~]#sort a.txt | uniq -c

2 1

2 2019

1 hello world

2 test

tee重定向命令:(与 > 重定向类似,区别在于tee命令在重定向时会打印重定向的内容)

[root@localhost ~]#sort a.txt | uniq -c

2 1

2 2019

1 hello world

2 test

[root@localhost ~]#sort a.txt |uniq -c |tee b.txt

2 1

2 2019

1 hello world

2 test

[root@localhost ~]#cat b.txt

2 1

2 2019

1 hello world

2 test

-a 参数:追加重定向

[root@localhost ~]#cat b.txt

2 1

2 2019

1 hello world

2 test

[root@localhost ~]#sort a.txt |uniq -c |tee -a b.txt

2 1

2 2019

1 hello world

2 test

[root@localhost ~]#cat b.txt

2 1

2 2019

1 hello world

2 test

2 1

2 2019

1 hello world

2 test

tr替换命令:(可以替换单个、多个及所以字符)

[root@localhost ~]#echo "hello world"

hello world

[root@localhost ~]#echo "hello world" |tr 'h' 'H'

Hello world

[root@localhost ~]#echo "hello world" |tr '[hw]' '[HW]'

Hello World

[root@localhost ~]#echo "hello world" |tr '[a-z]' '[A-Z]'

HELLO WORLD

[root@localhost ~]#echo "hello world" |tr '[a-z]' '0'

00000 00000

split切割命令:(通常用于切割大日志文件)

-b参数:指定切割大小(不指定单位的情况下默认是字节)

[root@localhost ~]#find /etc/ -type f -exec cat {} > log.txt \;

[root@localhost ~]#ls -lh

总用量 27M

-rw-r--r--. 1 root root 27M 9月 17 22:44 log.txt

[root@localhost ~]#split -b 10M log.txt

[root@localhost ~]#du -sh *

27M log.txt

10M xaa

10M xab

6.1M xac

切割的同时可以指定文件前缀:

[root@localhost ~]#split -b 10M log.txt testlog.

[root@localhost ~]#ls

log.txt testlog.aa testlog.ab testlog.ac

-l 参数:按行数切割

[root@localhost ~]#split -l 60000 log.txt

[root@localhost ~]#wc -l *

170640 log.txt

60000 xaa

60000 xab

50640 xac

341280 总用量

linux分割内容单引号,linux变量、cut_sort_wc_uniq_tee_tr_split 命令使用方法相关推荐

  1. linux shell sed 单引号, 双引号,反引号, 斜杆, 反斜杆(‘ “ ` / \)

    前言: 来看这个内容的,估计和我一样被绕晕了, 找不到规则.其实这是shell比较灵活导致的. 其实遵循如下原则可以避免莫名其妙的意外(少掉头发). 1) 坚决不使用反引号(`),  坚决使用$() ...

  2. sed -i 单引号中嵌套双引号_【linux】Shell 单引号#x27;#x27; 双引号quot;quot; 反引号`` 和$()的区别和用法...

    发行版为 red hat 以及centos,其他发行版未经验证 部分段落摘抄自网络,侵删 转载请注明出处 感谢点赞 单引号''和双引号"" 两者都是解决变量中间有空格的问题. 在b ...

  3. linux中特殊字符反引号,linux中的特殊符号$ ‘’ 反引号 反斜杠

    写在前面:Shell中的特殊字符有 $ 美元符 \ 反斜杠 ` 反引号 "双引号 < ,>;,*,?,[,] 1.反引号``:命令替换 在输出一句话的时候,如果想中间加入命令输出 ...

  4. 描述linux shell单引号,Linux shell 单引号和双引号

    在编写shell脚本的时候经常会用到引号,有些时候却老是忘记单引号和双引号之间的区别, 所以就整理一下供以后脑子不好使了的时候前来复习一下.首先说下他们的共同点: 好像就只有 一个,就是它们都可以用来 ...

  5. lua读取linux文件内容,使用lua模拟tail -n命令读取最后n行

    文章目录 [隐藏] 实现思路 lua代码 用法 最近需要使用lua读取文件的最后n行数据,但不想调用linux中的tail命令来获取,于是使用纯lua来实现. 实现思路 把文件指针偏移距离文件尾x个字 ...

  6. linux统计文件单词数,Linux怎么统计文本的的行数/单词数和字符数?

    Linux系统中想要统计文本的行数.单词和字符数量,该怎么统计呢?我们可以使用SecureCRT来统计,下面我们就来看看详细的教程. 1.启动Linux系统,用SecureCRT(或者其他的ssh工具 ...

  7. linux显示文件内容行号,linux命令显示文件内容行号|linux将内容以行号显示出来...

    linux命令 显示文件内容 通过命令+文件名查看内容.如下命令可以查看.1, cat :由第一行开始显示文件内容:2,tac:从最后一行开始显示,可以看出tac与cat字母顺序相反:3,nl:显示的 ...

  8. 对Linux课程内容的建议,Linux课程笔记 Day01 课程内容总结(示例代码)

    系统安装: 引导项简单介绍:在"boot:"提示后: 直接回车(Enter)--图形界面安装模式 linux text--字符界面安装模式 linux askmethod--提示用 ...

  9. linux 开启LACP 单端口,Linux 网桥支持LACP 报文透传的解决方法

    IEEE 802.1D MAC网桥过滤MAC组地址 LACP的协议是使用01-80-C2-00-00-0x范围内的MAC地址,这个范围在IEEE标准802.1D中定义为"MAC桥接过滤MAC ...

最新文章

  1. 用SQL删除重复记录的N种方法
  2. Android短信发送流程之多收件人发送(原)
  3. 机器学习实战之K近邻算法
  4. 二元函数图像生成器_GAN生成图像综述
  5. python django flask介绍,Django/Flask简介
  6. 软件工程文档软件测试,关于软件工程血的教训之文档管理
  7. 微信飞机小游戏java_Shoot Plane 仿微信打飞机游戏的java实现
  8. MTK Modem编译
  9. html5手机的注册页面,H5页面结合vue实现登录注册组件
  10. 当代移动通信发展四个阶段
  11. Isotropix Clarisse iFX Mac(CG渲染软件) v3.6破解版
  12. Go Tools安装
  13. 【线代】矩阵转置性质及代码证明
  14. C#多进程文件读写的锁处理
  15. 《Rework》读书笔记
  16. 解决每次弹出“是否允许XX录制/投射您的屏幕”(享做笔记、王者荣耀等)手把手教程
  17. FACIAL阅读笔记
  18. 自动化失败的6种原因
  19. Unity3d架构之-Unity MVC框架 StrangeIoC
  20. 常用材料的弹性模量、泊松比、密度

热门文章

  1. Pentium M处理器架构/微架构/流水线 (2) - 数据预取/乱序核/退役单元
  2. 二. 2d-2d 对极约束 估计相机位姿pose(R,t)
  3. matlab中ode45函数的用法_带你理解Excel中COUNTIF函数的简单用法
  4. zabbix模板_基于zabbix网页配置自定义tomcat监控模板--监控项、触发器
  5. 字典和键值对换输出_Python知识小结—字典
  6. python读取枚举_在python中枚举(enumerate in python)
  7. UE4 Hello Slate
  8. 移动终端CPU、GPU浅析
  9. MySQL数据库 --基础
  10. Bzoj1899: [Zjoi2004]Lunch 午餐