Linux命令行与shell脚本编程大全笔记(创建实用的脚本)

文件归档

exec < $config_file  #重定向输入
read FILE_NAME
while [ $? -eq 0 ]
do
	xxx
	read FILE_NAME
done
tar -czf test.tar  $file_list 2 > dev/null

管理用户账户

ps -u $USER_NAME > /dev/null
command1="ps -u $user_name --no-heading"
command3="xargs -d \\n /usr/bin/sudo /bin/kill -9"
$command1 |gawk '{print $1}' | $command3

检测磁盘空间

du -S $DIR 2>/dev/null |
sort -rn|
sed '{11,$D; =}' | # 前十个
sed 'N; s/\n/ /' | # 与行号行合并
gawk '{printf $1 ":" "\t" $2}'

数据库中使用脚本

MYSQL=$(which mysql)
$MYSQL mytest -u test << EOF
show tables;
select * from table where salary > 4000;
EOF

发送消息

mesg # 显示消息是否可用
who 
who -T # + 可用 - 不可用
write tra2 pst/0 # 向虚拟终端发送消息
hello world 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值