1. shell概述
shell是一个命令行解释器,接收用户操作指令,然后调用操作系统内核.
shell还是一个功能丰富的编程语言
2. shell解析器
cat /etc/shells
有 sh bash 等
3. 入门操作
写shell脚本, 文件首行 #!/bin/bash 指定解析器
脚本的执行 sh + 绝对或相对路径
如果赋予了脚本可执行权限,则可以直接使用相对路径和绝对路径执行脚本文件
4. 变量
系统变量直接 $JAVA_HOME
显示当前shell变量: set
$# 显示脚本输入参数个数
$n n为数字,获取脚本第n个参数,$0代表脚本名称,10以上的参数用大括号 ${10}
$* 获取所有参数,当做一个整体
$@ 获取所有参数,分开对待
$? (小朋友你是否有很多问号???) 判断上一个命令是否正确执行,0正确,非0错误
5. 加减乘除
(2+3)*4=20

-sh-4.2$ expr `expr 2 + 3` \* 4
20
-sh-4.2$ echo $[(2+3)*4]
20

6. 买大买小买定离手
[ 条件 ] : 判断true 和false,条件前后有空格
字符串比较: =
整数比较: -lt (less than) 小于 -le (less equal) 小于等于
-eq( equal) 等于 -gt (greater than) 大于
-ge( greater equal) 大于等于 -ne (not equal) 不等
权限判断: -r 读 -w 写 -x 执行
文件判断: -f 文件 -d 目录 -e 文件存在
7. 流程一条龙

if [ 条件 ];thenxxx
fi
if [ 条件 ]thenxxx
fi
case $变量 in"p1")xxx;;"p2")xxx;;*)xxx;;
for(( 初始值;循环条件:变量控制 ))doxxxdonefor((变量 in  v1 v2 v3))doxxxdone
while [ 条件 ]doxxxdone

8. 增删改查
8.1 cut

-sh-4.2$ cut --help
Usage: cut OPTION... [FILE]...
Print selected parts of lines from each FILE to standard output.Mandatory arguments to long options are mandatory for short options too.-b, --bytes=LIST        select only these bytes-c, --characters=LIST   select only these characters-d, --delimiter=DELIM   use DELIM instead of TAB for field delimiter-f, --fields=LIST       select only these fields;  also print any linethat contains no delimiter character, unlessthe -s option is specified-n                      with -b: don't split multibyte characters--complement        complement the set of selected bytes, charactersor fields-s, --only-delimited    do not print lines not containing delimiters--output-delimiter=STRING  use STRING as the output delimiterthe default is to use the input delimiter--help     display this help and exit--version  output version information and exitUse one, and only one of -b, -c or -f.  Each LIST is made up of one
range, or many ranges separated by commas.  Selected input is written
in the same order that it is read, and is written exactly once.
Each range is one of:N     N'th byte, character or field, counted from 1N-    from N'th byte, character or field, to end of lineN-M   from N'th to M'th (included) byte, character or field-M    from first to M'th (included) byte, character or fieldWith no FILE, or when FILE is -, read standard input.GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'cut invocation'

cut [参数] 文件名
默认分隔符为制表符
-f 列号,提取第几列
-d 分隔符,自定义分隔符分隔列

-sh-4.2$ echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0
-sh-4.2$ echo $JAVA_HOME|cut -d '/' -f 1-sh-4.2$ echo $JAVA_HOME|cut -d '/' -f 2
usr
-sh-4.2$ echo $JAVA_HOME|cut -d '/' -f 3
lib

8.2 sed
sed 一次处理一行数据,处理时把当前处理的行存储在临时缓冲区,sed 开始处理缓冲区中的内容,处理完了输出

-sh-4.2$ sed --help
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...-n, --quiet, --silentsuppress automatic printing of pattern space-e script, --expression=scriptadd the script to the commands to be executed-f script-file, --file=script-fileadd the contents of script-file to the commands to be executed--follow-symlinksfollow symlinks when processing in place-i[SUFFIX], --in-place[=SUFFIX]edit files in place (makes backup if SUFFIX supplied)-c, --copyuse copy instead of rename when shuffling files in -i mode-b, --binarydoes nothing; for compatibility with WIN32/CYGWIN/MSDOS/EMX (open files in binary mode (CR+LFs are not treated specially))-l N, --line-length=Nspecify the desired line-wrap length for the `l' command--posixdisable all GNU extensions.-r, --regexp-extendeduse extended regular expressions in the script.-s, --separateconsider files as separate rather than as a single continuouslong stream.-u, --unbufferedload minimal amounts of data from the input files and flushthe output buffers more often-z, --null-dataseparate lines by NUL characters--helpdisplay this help and exit--versionoutput version information and exit

-e 在指令模式上进行编辑
a 新增,a后面可以接一行字符串在下一行出现
d 删除
s 查找替换

-sh-4.2$ cat test.txt
aaaa bbb
cccd dsd
fsdf fsdf fsdf fsdfs
-sh-4.2$ sed 'a 6666' test.txt
aaaa bbb
6666
cccd dsd
6666
fsdf fsdf fsdf fsdfs
6666
-sh-4.2$ sed '1a 6666' test.txt
aaaa bbb
6666
cccd dsd
fsdf fsdf fsdf fsdfs
-sh-4.2$ sed '/aa/d' test.txt
cccd dsd
fsdf fsdf fsdf fsdfs
-sh-4.2$ sed 's/aa/666/' test.txt
666aa bbb
cccd dsd
fsdf fsdf fsdf fsdfs
-sh-4.2$ sed 's/aa/666/g' test.txt
666666 bbb
cccd dsd
fsdf fsdf fsdf fsdfs

8.3 awk
把文件逐行读入,空格Wie默认分隔符进行切片,切开部分再进行分析处理
awk [参数] ‘pattern{action}’ filename
-F 指定输入文件分隔符
-v 赋值一个用户定义变量

-sh-4.2$ cat test.txt
aaaa bbb
cccd dsd
ff fd fsf fqq
666
777 888
-sh-4.2$ awk -F' ' '/^f/{print $2}' test.txt
fd-sh-4.2$ cat test.txt
aaaa bbb
cccd dsd
ff fd fsf fqq
666
777 888
-sh-4.2$ awk -F' ' 'BEGIN{print "xxx,ddd"} {print} END{print "end 9999"}' test.txt
xxx,ddd
aaaa bbb
cccd dsd
ff fd fsf fqq
666
777 888
end 9999-sh-4.2$ cat test.txt
111 aaaa bbb
222 cccd dsd
333 ff fd fsf fqq
666
777 888
-sh-4.2$ awk -F' ' -v i=10 '/[0-9]*/{print $1*i}' test.txt
1110
2220
3330
6660
7770

awk内置变量: FILENAME 文件名 NR 已读的记录数 NF 浏览记录的域个数(切割后,列的个数)

-sh-4.2$ cat test.txt
111 aaaa bbb
222 cccd dsd
333 ff fd fsf fqq
666
777 888
-sh-4.2$ awk -F ' ' '{print "filename:" FILENAME " readnum:" NR " columns:" NF}' test.txt
filename:test.txt readnum:1 columns:3
filename:test.txt readnum:2 columns:3
filename:test.txt readnum:3 columns:5
filename:test.txt readnum:4 columns:1
filename:test.txt readnum:5 columns:2

8.4 sort
sort 参数
-n 按照数值的大小排序
-r 以相反的顺序来排序
-t 设置排序时所用的分隔字符
-k 指定需要排序的列

-sh-4.2$ cat test.txt
2 3
3 1
5 4
1 5
3 0
4 2
-sh-4.2$ sort -n test.txt
1 5
2 3
3 0
3 1
4 2
5 4
-sh-4.2$ sort -nr test.txt
5 4
4 2
3 1
3 0
2 3
1 5
-sh-4.2$ sort -nk 2 test.txt
3 0
3 1
4 2
2 3
5 4
1 5
-sh-4.2$ sort -nrk 2 test.txt
1 5
5 4
2 3
4 2
3 1
3 0

Linux.2- shell命令(部分)相关推荐

  1. 八、Linux 常用 Shell 命令,控制台的快捷键以及 Shell 编程(中)

    @Author : Runsen @Date:2020/9/11 文章是Runsen在Gitchat付费文章分享:Linux 常用 Shell 命令,控制台的快捷键以及 Shell 编程 顺便同步到C ...

  2. 七、Linux 常用 Shell 命令,控制台的快捷键以及 Shell 编程(上)

    @Author : Runsen @Date:2020/9/11 文章是Gitchat付费文章分享:Linux 常用 Shell 命令,控制台的快捷键以及 Shell 编程 顺便同步到CSDN中,这里 ...

  3. Python下调用Linux的Shell命令

    转载:http://blog.csdn.net/my2010sam/article/details/18315785 有时候难免需要直接调用Shell命令来完成一些比较简单的操作,比如mount一个文 ...

  4. python shell运行当前程序、可以按下_Python下调用Linux的Shell命令的方法

    有时候难免需要直接调用Shell命令来完成一些比较简单的操作,比如mount一个文件系统之类的.那么我们使用Python如何调用Linux的Shell命令?下面来介绍几种常用的方法: 1. os 模块 ...

  5. sharpssh远程linux监控系统,利用SharpSsh远程执行linux的shell命令

    利用SharpSsh远程执行linux的shell命令 (2011-07-26 14:38:02) SharpSSH是一个C#的开源项目,可以利用SSH连接linux系统.并执行shell等命令. 而 ...

  6. Linux基础(2)--Linux常用shell命令

    Linux常用shell命令 显示命令 查看当前工作路径 切换目录 清屏 显示和配置网络属性 新建文件夹 删除命令 压缩和解压命令 拷贝命令 帮助命令man 显示命令 – 命令:ls – 参数:a,l ...

  7. linux命令执行的通过程,Linux下shell命令执行过程简介

    浅析linux 下shell命令执行和守护进程 执行shell脚本有以下几种方式 1.相对路径方式,需先cd到脚本路径下 [root@banking tmp]# cd /tmp [root@banki ...

  8. Linux脚本Shell命令

    在向大家详细介绍linux编译之前,首先让大家了解下Linux脚本Shell命令.然后讲解在shell脚本中可以使用任意的unix命令. 语法基本介绍 1.开头 程序必须以下面的行开始(必须方在文件的 ...

  9. linux中安shell怎么传入参数,【linux】linux 下 shell命令 执行结果赋值给变量【两种方式】...

    方法1:[通用方法] 使用Tab键上面的反引号 例子如下: find命令 模糊查询在/apps/swapping目录下 查找 文件名中包含swapping并且以.jar结尾的文件 使用反引号 引住命令 ...

  10. Linux 下 Shell 命令 IFS 分隔符 -- 应用场景 解决办法

    Linux 下 Shell 命令 IFS 分隔符 – 应用场景 && 解决办法 文章目录 Linux 下 Shell 命令 IFS 分隔符 -- 应用场景 && 解决办 ...

最新文章

  1. AAAI-19 日程 安排
  2. 字典树(前缀树)-Java实现
  3. WorldWind Java 版学习:8、事件响应
  4. 技术博客(初用markdown)。
  5. 如何快速直接从Web of Science下载文献,保存到Endnote
  6. 【Wax】使用Wax (framework方式,XCode 4.6)
  7. [转]python新手必碰到的问题---encode与decode,中文乱码--转载
  8. 3-3.HDFS项目实战目标和要求
  9. 格式 数组的基本使用 0912
  10. jQuery 3.5.0 发布
  11. windbg使用教程: 具体实例
  12. 发力大数据营销 神马搜索获年度最佳移动广告平台奖
  13. 那些好用的 GIF 录制工具
  14. 复数乘法的交换律、结合律及乘法 对加法的分配律证明过程
  15. android的app图标大全,安卓app图标
  16. Control Egress TCP Traffic
  17. 学习自旋电子学的笔记06:“扫参数”批量微磁模拟,ubermag介绍,微磁模拟求助
  18. Linux 基本管理命令(系统管理,用户管理,进程管理)
  19. json toBean使用
  20. 996公司太累?那国企到底面试些什么干货,详细答案)

热门文章

  1. 20155218 《Java程序设计》实验二(Java面向对象程序设计)实验报告
  2. 压缩包文件密码如何解密
  3. Error: Getter not found: 'suspending'. case AppLifecycleState.suspending
  4. java method方法_java入门(六) | 方法(Method)的定义和使用
  5. linux设置双屏拼接_Linux下双屏显示设置
  6. php定做单城市公交路线查询系统
  7. Router-view
  8. Springboot使用POI读写excel(详细)
  9. 百度地图迁徙大数据_百度地图迁徙大数据:复工后北上广深城内出行年后首次大幅增长...
  10. 手机app网易邮箱服务器设置,网易邮箱默认开通IMAP服务