Linux命令集合

批量更名文件bash

for var in `ls *.bak`;do mv -f "$var" `echo "$var"|sed 's/....$//'`;done     //将去除文件名字后面的 .bak
for var in `ls *.bak`;do mv -f "$var" `echo "$var"|sed 's/...$/xxx/'`;done  //将文件名字最后的三个字符改成 xxx

 查找/etc目录下大于1M的文件,并将其文件名写入/tmp/etc.largefiles文件中;服务器

find /etc -size +1M -exec echo {} >> /tmp/etc.largefiles \;
find /etc -size +1M >> /tmp/etc.largefiles

删除类型不是目录,并且没有属主的文件;网络

find / -not -type d -a -nouser -exec rm -f {} \;
find / -not -type d -a -nouser | xargs -i rm -f {}

 使用scp命令复制另一台的文件到当前目录下面ssh

scp -rp root@192.168.137.16:/root/.   ./      #注意/root/. root后面的 . 要加上,它复制的是这个目录下面的全部文件包含隐藏文件,不然不成功

 复制目录排除目录里面的某个文件夹或者文件,注意:--exclude后面必须是相对路径,使用绝对路径不行工具

rsync -av --exclude yum.log --exclude ks-script-rTogPV /tmp/ /tmp-li/

 ssh的免密登录,说明:不少公司是禁止root直接登录的,所以设置了root的免密登录,会提示权限拒绝,spa

免密登录的原理就是:将a服务器生成的后缀为.pub的文件内容复制到 b服务器的家目录下面的.ssh下面的 authorized_keys文件里面,而且权限为600,a就能够免密访问b服务器code

ssh-keygen -t rsa  #一路回车
ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.137.3 #这个是单向的
ssh-copy-id -i /root/.ssh/id_rsa.ub cdp@192.168.137.3 #设置一个从root无密码使用cdp用户登录到其余服务器,其余服务器上面的cdp 要执行 ssh-keygen -t rsa

 远程使用sudo方式不切换root,执行root的命令blog

sudo -i -u root -- sh -c  "ls;echo "------------";whoami"
sudo -i -u root -- sh -c "\cp /home/li/*.jar /tmp/jenkins-linshi/ ;bash /tmp/jenkins-linshi/test.sh"

 sshpass远程登录并带入密码,执行命令,-p后面接密码,特殊符号要使用 \ip

/usr/local/sshpass/bin/sshpass -p cbi\@123\!\@\# ssh  -p 22222 cbi@10.122.1.1 "ps -ef|grep $1|grep -v grep"

 find命令排除某个目录开发

find / -path "/data" -prune -o -name "*.log" -print

————————————————————sh-----------------

sh -n 检查语法错误,但不执行
sh -x  进入跟踪方式,显示所执行的每一条命令的执行结果

 找出两个文件中相同的行

grep -Ff a.txt b.txt

 在远程执行命令,并在本地回显

ssh root@ip  'bash -x -s' </data/sh/auto_deploy_script.sh

 删除文件或者目录,只留下想要的文件或者目录

只留下 3.txt 7.txt m1 m4 其余通通删除
[root@localhost test]# touch {1,2,3,4,5,6,7}.txt [root@localhost test]# ls 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt [root@localhost test]# mkdir m{1,2,3,4} [root@localhost test]# ls 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt m1 m2 m3 m4 [root@localhost test]# ls m1 [root@localhost test]# rm -rf `ls | egrep -v '(3.txt|7.txt|m1|m4)'` [root@localhost test]# ls 3.txt 7.txt m1 m4

 Linux查看时区

[root@localhost backup]# timedatectl
      Local time: 三 2019-08-28 01:10:43 CST
  Universal time: 二 2019-08-27 17:10:43 UTC
        RTC time: 二 2019-08-27 17:10:43
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@localhost backup]# timedatectl|grep "Time zone"
       Time zone: Asia/Shanghai (CST, +0800)
[root@localhost backup]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@localhost backup]# 

[root@localhost backup]# date +"%Z %z"
CST +0800

 

 

 

 

 

iptraf-ng

yum -y install iptraf-ng

iptraf是一个基于ncurses开发的IP局域网监控工具,它能够实时地监视网卡流量,能够生成各类网络统计数据,

包括TCP信息、UDP统计、ICMP和OSPF信息、以太网负载信息、节点统计、IP校验和错误和其它一些信息。

 nload:查看网卡的进出流量

yum  -y install  nload

nload ens33 #查看指定的网卡

相关文章
相关标签/搜索