Shell

作者: 菜菜子MJ | 来源:发表于2019-08-05 12:02 被阅读0次
  • awk
#输出每行的第一列并添加“test/”前缀
cat test_xv.txt | awk '{print "test/" $1}' > test.txt
  • bc 任意精度计算器
#保留2位小数
echo 'scale=2; (2.777 - 1.4744)/1' | bc
#输入按2进制,输出按10进制,结果为192
echo "obase=10;ibase=2;11000000 " | bc
#计算结果加上前导0,存入变量(bc的计算结果默认不含前导0),计算保留5位精度,输出保留3位精度
total_time=`echo "scale=5;${total_time} + ${time_s_single}" | bc | awk '{printf "%.3f", $0}'`
  • cp 拷贝
# 拷贝时排除某些文件
cp `ls /source_dir | grep -v no_need_file.txt | xargs` /target_dir
  • cut
#指定分隔符“:”,提取第3,第5列
cut -d':' -f3,5
#指定分隔符“:”,提取第1-3列
cut -d ':' -f 1-3
  • dd
#转换并复制文件,转换16位大小端
dd conv=swab if=s16be.pcm of=s16le.pcm
  • echo
#原样输出字符串,不进行转义或取变量(用单引号)
echo '$name\"'
#显示命令执行结果
echo `date`
#显示结果定向至文件
echo "It is a test" > myfile
  • expr 表达式求值(运算符前后必须有空格)
#求值30*3
expr 30 \* 3 
  • grep
#排除包含xxx的行
grep -v "xxx" 
# ^ 行前缀匹配,排除xxx开头的行
grep -v "^xxx" 
  • if 条件判断
#判断文件是否存在
if [ -f $1/$file ]; then

else

fi
  • ln
# -s 创建软连接
ln -s 源文件 目标文件
# -snf 修改软连接 -n 把符号链接视为一般目录 -f 强制执行
ln -snf 新源文件 目标文件
  • sed 文本替换
# g 表示全局替换
sed 's/$old/$new/g' 
  • sort 排序
#按字典序排序
sort
  • split
#把文件按每10行分割, 3个数字作为后缀,split作为前缀
split -l 10 file.txt  -d -a 3 split
  • tee
#将test输出到屏幕,同时以追加的方式输出到test.log文件
echo "test" | tee -a test.log 
  • xargs
#多行输入单行输出
cat test.txt | xargs
#多行输入,每行3个单词输出
cat test.txt | xargs -n3

相关文章

  • Shell 学习

    shell 变量 shell 参数传递 shell 数组 shell 运算符 shell echo 命令 prin...

  • Shell 概述

    学习 Shell 主要包括的内容: Shell 脚本入门 Shell 变量 Shell 内置命令 Shell 运算...

  • Shell 教程

    Shell 变量 Shell 传递参数 Shell 数组 Shell 基本运算符 Shell echo 命令 Sh...

  • shell 第一天

    shell编程初识 1.1 shell编程初识 shell的定义 Shell 是命令解释器 Shell 也是...

  • shell 案例

    Shell编程一 Shell防范ARP攻击 Shell编程二 Shell防范DDos攻击 Shell编程三 ...

  • 【生物信息笔记】shell 脚本 (dry-2)

    shell 和 shell script(脚本)区别: shell 和 shell 脚本是两个不同概念,shell...

  • Linux Shell:基础知识和Shell变量

    摘要:Linux,Shell 整理Shell内容要点: Shell基础知识 Shell变量的类型 Shell变量赋...

  • Shell脚本语言一

    一、语法 格式 运行 Shell变量 Shell字符串 Shell数组 Shell注释 Shell传递参数 She...

  • 使用shell脚本

    使用方式 shell 变量 shell 字符串操作 shell 数组 shell 注释 shell 命令行参数 s...

  • vim学习 09——shell命令

    vim学习 09——shell命令 执行 shell 命令 :!shell命令 : 可以执行 shell 命令。 ...

网友评论

      本文标题:Shell

      本文链接:https://www.haomeiwen.com/subject/akopdctx.html