(22)linux小技巧

【1】常见小技巧

【1.0】脚本汇总

sudo echo "export TIME_STYLE='+%Y-%m-%d %H:%M:%S'" >> /etc/profile && source /etc/profile
sudo echo "export PS1='[\u@\h \w]$ '">>/etc/profile && source /etc/profile
echo 'export HISTTIMEFORMAT="%F %T"' >>/etc/profile && source /etc/profile
echo "unset MAILCHECK">> /etc/profile

【1.1】以年-月-日格式显示日期

sudo echo "export TIME_STYLE='+%Y-%m-%d %H:%M:%S'" >> /etc/profile && source /etc/profile

【1.2】linux显示当前路径的绝对路径

具体参考:https://www.cnblogs.com/gered/p/11364053.html

sudo echo "export PS1='[\u@\h \w]$ '">>/etc/profile && source /etc/profile

【1.3】删除过滤出来的文件

#删除当前目录下,不包含aaa的所有文件
ll |grep -v "aaa"|grep .sql|awk '{print $NF}'|xargs rm -f

【1.4】tar

https://www.cnblogs.com/centos2017/p/7896807.html

【1.5】history命令显示时间

echo 'export HISTTIMEFORMAT="%F %T "' >>/etc/profile  && source /etc/profile

【1.6】dhcp重新分配ip地址

dhclient -r #释放现有ip
dhclient    #获取新ip

【1.7】linux 查看外网出口地址

curl -s http://httpbin.org/ip

【1.8】使用 PS1 让命令窗口上显示时间

PS1='[\u@\h \d \A \W]\$ '

效果:
[root@localhost Fri Apr 01 14:26 ~]# 

【1.9】解决 you have a mail in /var/spool/mail

echo "unset MAILCHECK">> /etc/profile
source /etc/profile
ls -lth /var/spool/mail
cat /dev/null > /var/spool/mail/root

 

【命令小技巧】

(1)xargs 配合 scp

ls 20210803*|grep `date +%Y-%m-%d`|xargs -i scp {} dba@47.103.129.219:/data/backup/10.112.5.1

(2)四则运算 let a=4+6 b=9*2 

[root@fc_log_db_4_8 ~]# let a=4+6 b=9*2 
[root@fc_log_db_4_8 ~]# echo $a $b
10 18
[root@fc_log_db_4_8 ~]# let a=$a+$b
[root@fc_log_db_4_8 ~]# echo $a
28

【参考文档】

【查阅】shell常见技巧

posted @ 2021-03-29 17:05  郭大侠1  阅读(82)  评论(0编辑  收藏  举报