Shell脚本小技巧收集

1.使用python快速搭建一个web服务器

访问端口8000

python -m SimpleHTTPServer

2.获取文件大小

stat -c %s $file
stat --printf='%s
' $file
wc -c $file

3.多进程管理工具

yum install supervisor -y

4.linux多线程下载工具

yum install axel -y

5.read命令退格问题

#在read命令前使用这个就好了
stty erase ^H

6.密码生成工具

yum install pwgen -y
# 生成20位随机密码
[root@test ~]# pwgen -c1 20
Jae1geerohbukec9ooQu

7.快速获取java进程pid

pgrep java
-o:仅显示找到的最小(起始)进程号;
-n:仅显示找到的最大(结束)进程号;
-l:显示进程名称;
-P:指定父进程号;
-g:指定进程组;
-t:指定开启进程的终端;
-u:指定进程的有效用户ID。

pgrep -u root,daemon java
#将列出由root或守护进程拥有的java进程。

合并文件的列

Linux paste命令用于合并文件的列。

paste指令会把每个文件以列对列的方式,一列列地加以合并。

语法
paste [-s][-d <间隔字符>][--help][--version][文件...]
参数:

-d<间隔字符>或--delimiters=<间隔字符>  用指定的间隔字符取代跳格字符。
-s或--serial  串列进行而非平行处理。

批量修改文件名

[root@lb-A2 web-manager]# ls
testmboss.yoho8.com.conf     testmhome.yoho8.com.conf  testmproduct.yoho8.com.conf  testmuser.yoho8.com.conf
testmbuyloan.yoho8.com.conf  testmoms.yoho8.com.conf   testmpromo.yoho8.com.conf
testmfinance.yoho8.com.conf  testmpop.yoho8.com.conf   testmrisk.yoho8.com.conf

[root@lb-A2 web-manager]# rename testm test2m testm*
[root@lb-A2 web-manager]# ls
test2mboss.yoho8.com.conf     test2mhome.yoho8.com.conf  test2mproduct.yoho8.com.conf  test2muser.yoho8.com.conf
test2mbuyloan.yoho8.com.conf  test2moms.yoho8.com.conf   test2mpromo.yoho8.com.conf
test2mfinance.yoho8.com.conf  test2mpop.yoho8.com.conf   test2mrisk.yoho8.com.conf
原文地址:https://www.cnblogs.com/Csir/p/8310168.html