美文网首页
shell 常用命令备忘

shell 常用命令备忘

作者: 后知不觉1 | 来源:发表于2021-03-10 14:22 被阅读0次

文本处理

#两行合成一行
 cat  Downloads/asd.txt | sed 'N;s/\n/ /'
#三行合并一行
cat asd.txt | sed 'N;N;s/\n/ /g'
#四行合并一行
cat asd.txt | sed 'N;N;N;s/\n/ /g'
#添加字符串行
cat asd.txt | sed  '1i[sf-cluster]' 

sed '/asd/casd/'  asd.txt  #将asd.txt文件中包含asd的行替换为asd
sed '/asd/sasd/'  asd.txt  #将asd.txt文件中asd字符替换为asd

linux 自动补全

    #安装自动补全组件
     yum install -y bash-completion
  
    #配置补全命令,这个在ssh 时将hosts 、history 中主机补全
    complete -W "$(echo $(cat /etc/hosts | awk '{print $2}'| sed 's/^ssh //')) $(history | sed 's/^[ ]*[0-9]\+[ ]*//' | grep ^ssh | awk '{print $2}')" ssh

linux 管道符中的占位符传递

  xargs -i{}   bash -c "ps -ef | grep {}"

ansible

# 建立定时任务  每小时重置一下免密
ansible asd-m cron -a "name=\"reset sshd\" job=\"sed -i '/PermitRootLogin/cPermitRootLogin yes' /etc/ssh/sshd_config && systemctl restart sshd\" hour=*/1"
# 删除定时任务
ansible asd-m cron -a  'name="reset sshd" state=absent'

# 修改hostname
ansible $temp_group -m shell -a "cp /etc/hostname /etc/hostnamebak" 
ansible $temp_group -m shell -a "echo {{ inventory_hostname }}> /etc/hostname" 
ansible $temp_group -m shell -a "hostnamectl set-hostname {{ inventory_hostname }}" 

# 通过密码打通免密
ansible $temp_group -m authorized_key -a "user=root key='{{ lookup('file', '/root/.ssh/id_rsa.pub')}}' path='/root/.ssh/authorized_keys'" 

dgraph图库安装

nohup /app/dgraph/dgraph-ratel -port 8050 > ratel.log 2>&1 &
nohup /app/dgraph/dgraph zero --port_offset 100 --my sfmap-vl23325:5180 --replicas 3  > zero.log  2>&1 &
nohup /app/dgraph/dgraph alpha --lru_mb 2048 --port_offset 100 --my sfmap-vl23325:7180 --zero sfmap-vl23325:5180 --whitelist 0.0.0.0/0 > alpha.log  2>&1 &
nohup /app/dgraph/dgraph alpha --lru_mb 2048 --port_offset 100 --my sfmap-vl23326:7180 --zero sfmap-vl23325:5180 --whitelist 0.0.0.0/0 > alpha.log  2>&1 &
nohup /app/dgraph/dgraph alpha --lru_mb 2048 --port_offset 100 --my sfmap-vl23327:7180 --zero sfmap-vl23325:5180 --whitelist 0.0.0.0/0 > alpha.log  2>&1 &

解析配置文件

循环读取文件内容

while read line
do
   echo $line
done < mysql.conf

字符串拼接

  1. 由单引号' '包围的字符串:
    任何字符都会原样输出,在其中使用变量是无效的。
    字符串中不能出现单引号,即使对单引号进行转义也不行。

  2. 由双引号" "包围的字符串:
    如果其中包含了某个变量,那么该变量会被解析(得到该变量的值),而不是原样输出。
    字符串中可以出现双引号,只要它被转义了就行。

相关文章

  • shell 常用命令备忘

    文本处理 linux 自动补全 linux 管道符中的占位符传递 ansible dgraph图库安装 解析配置文...

  • Shell命令汇总

    1、一般常用命令 (1)Shell 常用命令总结 (2)Shell的18条常用命令整理 2、文件操作常用命令 (1...

  • HBASE SHELL常用命令

    HBASE SHELL常用命令 标签: HBase Shell 1. 进入hbase shell console ...

  • Shell参考资料

    shell 目录 Shell简介 Shell常用命令 Shell里面的括号 Shell里面的单引号和双引号 She...

  • Shell脚本

    shell脚本学习笔记 shell命令的组合运用 常用命令组合

  • git命令整理

    git常用命令 GIT常用命令备忘:http://stormzhang.com/git/2014/01/27/gi...

  • unix常用命令

    UNIX操作指引 目录 1 Shell常用命令.....................................

  • shell 备忘

    shell脚本调试 参见:https://www.cyberciti.biz/tips/debugging-she...

  • Shell编程、part1

    1.shell简介2. shell分类3. 查看shell4. 第一个shell脚本5. shell编程常用命令5...

  • 子Shell脚本实现方式1-来自《跟老男孩学Linux运维:Sh

    [记录备忘][研究学习]通过Shell脚本来实现一个由“&”产生的子Shell

网友评论

      本文标题:shell 常用命令备忘

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