forever杨的个人博客

I want to be forever young!


  • 首页

  • 文章202

  • 分类31

  • 标签175

  • 公益

  • 关于

  • 搜索

Linux find 命令

发表于 2018-02-06 | 更新于 2020-12-09 | 分类于 Linux
| 字数: 442 | 时长 ≈ 1 分钟
标签 shell find

查找文件并删除

1
2
3
4
5
6
7
8
9
10
11
12
# 删除指定时间前的 jpg 文件
find /opt/upload/ -mtime +30 -type f -name *.jpg -exec rm -f {} \;

# 删除隐藏文件(-fr)
find /opt/upload/ -type d -name .svn -exec rm -fr {} \;

# 删除30天前的文件
find /opt/upload -mtime +30 -type f -name "*.jpg" -exec rm -rf {} \;


# find: 路径必须在表达式之前,在*前加\
find /opt/upload/ -mtime +15 -type f -name \*.log -exec rm -f {} \;

打印指定时间前的文件

1
find project/upload/ -mtime +30 -type f -print

Linux crontab 命令

发表于 2018-02-06 | 更新于 2021-09-15 | 分类于 Linux
| 字数: 968 | 时长 ≈ 1 分钟
标签 shell crontab

crontab 使用注意事项

如果通过 crontab 执行
1、crontab 无法获取 jdk 变量,要在 java 命令之前写入jdk绝对路径
2、要把路径切换到要执行的 sh 路径下
注意:二者缺一不可

阅读全文 »

Linux curl 命令

发表于 2018-02-06 | 更新于 2024-06-27 | 分类于 Linux
| 字数: 1.4k | 时长 ≈ 1 分钟
标签 shell curl

查询出口IP

1
2
3
4
5
6
7
8
9
10
curl icanhazip.com
curl ifconfig.me
curl ident.me
curl ipecho.net/plain
curl whatismyip.akamai.com
curl tnx.nl/ip
curl myip.dnsomatic.com
curl ip.appspot.com
curl ip.telize.com
curl curlmyip.com

GET 请求

1
curl https://www.baidu.com?q=xxxx

POST 请求

1
curl http://ip:port/api/add_user -XPOST -d "send message..."

发送 POST JSON 请求

1
curl -H "Content-Type: application/json" -X POST  --data '{"data":"1"}' http://127.0.0.1/

使用代理

1
curl -x 192.168.2.5:3128 https://www.baidu.com?q=xxxx

输出请求信息

1
2
3
4
5
6
7
8
# http_code
# time_connect
# time_starttransfer
# time_total
# size_download
# speed_download
# 参考地址:
curl http://www.baidu.com?q=xxxx -so /dev/null -w "%{http_code}\t%{time_connect}\t%{time_starttransfer}\t%{time_total}\t%{size_download}\t%{speed_download}\t"

下载文件并重命名

1
2
# culr -L <url> -o <filename>
curl -L http://mirrors.aliyun.com/repo/Centos-7.repo -o /etc/yum.repos.d/CentOS-Base.repo \

发送邮件

1
2
3
4
5
6
7
8
9
10
11
# mail.txt 内容
tee ./mail.txt <<-'EOF'
From:test01@163.com
To:test02@163.com
Subject: test send email

test send email!!!!!!
EOF

# 发送邮件
curl -s --url "smtp://smtp.163.net" --mail-from "test01@163.com" --user "test01@163.com:123456" --mail-rcpt "test02@163.com" --upload-file mail.txt

参数说明

  • –url:邮箱服务
  • –mail-from:发送者邮箱
  • –user:发送正邮箱账号密码,账号密码使用冒号隔开
  • – mail-rcpt:接收者邮箱
  • –upload-file:邮件内容,写法参考 mail.txt

Linux du 命令

发表于 2018-02-06 | 更新于 2024-05-06 | 分类于 Linux
| 字数: 87 | 时长 ≈ 1 分钟
标签 shell du

du

计算当前文件夹下占用空间,排序

1
2
3
du -sh /* | sort -nr
# 排除某个目录
du -sh /* --exclude="/data" | sort -nr

Linux grep 命令

发表于 2018-02-06 | 更新于 2024-03-05 | 分类于 Linux
| 字数: 509 | 时长 ≈ 1 分钟
标签 shell grep

grep

统计出现次数

1
grep 'sign.*time.*openid' access_p80_weixinv3.log | awk '{a[$1]++}END{for(i in a)print a[i]"\t"i}' | sort -n

4 183.3.234.45
10 183.3.234.57
20 183.3.234.58

分组统计

1
grep -o "正则表达式" temp.txt | sort |uniq -c |sort -k1,1nr

查询前后日志

grep -5 ‘parttern’ inputfile //打印匹配行的前后5行
grep -C 5 ‘parttern’ inputfile //打印匹配行的前后5行
grep -A 5 ‘parttern’ inputfile //打印匹配行的后5行
grep -B 5 ‘parttern’ inputfile //打印匹配行的前5行

正则:数字

1
2
# 正则匹配1802****269的手机号码
grep '1802[0-9]\{4\}269' info.log

Linux ls 命令

发表于 2018-02-06 | 更新于 2021-05-11 | 分类于 Linux
| 字数: 138 | 时长 ≈ 1 分钟
标签 shell ls

ls

1
2
# 统计文件夹中文件数
ls -l |grep "^-"|wc -l

保留最新的1个文件夹,删除其他文件夹(使用-d)

1
ls -t -d /home/yl/api-web-open/logs/undertow-* | tail -n +2 | xargs rm -rf

Linux lsof 命令

发表于 2018-02-06 | 更新于 2023-04-27 | 分类于 Linux
| 字数: 3.2k | 时长 ≈ 3 分钟
标签 lsof shell

检测端口未被占用

1
lsof -i:<port>

指定进程号,可以查看该进程打开的文件

1
lsof -p <pid>

查询所有进程的 open files 数量

1
2
3
4
5
6
7
8
9
10
11
psof_file=~/psof.txt
# 每次执行前,清空 psof_file 文件内容
echo "" > $psof_file
# $(ps -eo pid | grep -v PID) 获取所有进程 id
for pid in $(ps -eo pid | grep -v PID)
# 查询进程的 open files 数量
do echo $pid":"$(lsof -p $pid|wc -l) >> $psof_file;
# do echo $pid":"$(lsof -n|grep $pid|wc -l) >> $psof_file;
done
# 对结果进行排序
sort -nrk 2 -t: $psof_file

统计各进程打开句柄数:lsof -n|awk ‘{print $2}’|sort|uniq -c|sort -nr

统计各用户打开句柄数:lsof -n|awk ‘{print $3}’|sort|uniq -c|sort -nr

统计各命令打开句柄数:lsof -n|awk ‘{print $1}’|sort|uniq -c|sort -nr

第一列是打开的句柄数,第二列是进程ID。

查看打开句柄总数
lsof -n|awk ‘{print $2}’|wc -l
查看系统中进程占用的句柄数,根据打开文件句柄的数量降序排列,其中第二列为进程ID:
lsof -n|awk ‘{print $2}’|sort|uniq -c|sort -nr|more
查询系统中指定进程占用的句柄数
lsof -n | grep [PID]| wc -l

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[root@grg-zhtest1 ~]# lsof -h
lsof 4.87
latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]
[-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
[+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.
-?|-h list help -a AND selections (OR) -b avoid kernel blocks
-c c cmd c ^c /c/[bix] +c w COMMAND width (9) +d s dir s files
-d s select by FD set +D D dir D tree *SLOW?* +|-e s exempt s *RISKY*
-i select IPv[46] files -K list tasKs (threads) -l list UID numbers
-n no host names -N select NFS files -o list file offset
-O no overhead *RISKY* -P no port names -R list paRent PID
-s list file size -t terse listing -T disable TCP/TPI info
-U select Unix socket -v list version info -V verbose search
+|-w Warnings (+) -X skip TCP&UDP* files -Z Z context [Z]
-- end option scan
+f|-f +filesystem or -file names +|-f[gG] flaGs
-F [f] select fields; -F? for help
+|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)
+m [m] use|create mount supplement
+|-M portMap registration (-) -o o o 0t offset digits (8)
-p s exclude(^)|select PIDs -S [t] t second stat timeout (15)
-T qs TCP/TPI Q,St (s) info
-g [s] exclude(^)|select and print process group IDs
-i i select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list]
+|-r [t[m<fmt>]] repeat every t seconds (15); + until no files, - forever.
An optional suffix to t is m<fmt>; m must separate t from <fmt> and
<fmt> is an strftime(3) format for the marker line.
-s p:s exclude(^)|select protocol (p = TCP|UDP) states by name(s).
-u s exclude(^)|select login|UID set s
-x [fl] cross over +d|+D File systems or symbolic Links
names select named files or files on named file systems
Anyone can list all files; /dev warnings disabled; kernel ID check disabled.

Linux netstat 命令

发表于 2018-02-06 | 更新于 2022-06-29 | 分类于 Linux
| 字数: 1.3k | 时长 ≈ 1 分钟
标签 netstat shell

netstat

netstat

通过进程查看占用端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# netstat -nap | grep 9836
$ netstat -anp | grep <pid>
tcp 0 0 0.0.0.0:8880 0.0.0.0:* LISTEN 15910/java
tcp 0 0 0.0.0.0:8881 0.0.0.0:* LISTEN 20854/java
tcp 0 0 0.0.0.0:8883 0.0.0.0:* LISTEN 18394/docker-proxy
tcp6 0 0 :::8883 :::* LISTEN 18400/docker-proxy
unix 2 [ ACC ] STREAM LISTENING 230283 17888/containerd-sh /run/containerd/s/f54f5c6b3963ea8fcec7d3c2baefa7fcb70884d50299148a00d747cc3c59980d
unix 3 [ ] STREAM CONNECTED 234595 17888/containerd-sh
unix 3 [ ] STREAM CONNECTED 229049 17888/containerd-sh /run/containerd/s/f54f5c6b3963ea8fcec7d3c2baefa7fcb70884d50299148a00d747cc3c59980d

$ netstat -anl|grep 888
tcp 0 0 0.0.0.0:8880 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8881 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8883 0.0.0.0:* LISTEN
tcp6 0 0 :::8883 :::* LISTEN

Linux sed 命令

发表于 2018-02-06 | 更新于 2021-03-01 | 分类于 Linux
| 字数: 64 | 时长 ≈ 1 分钟
标签 shell sed

sed

打印指定行数

1
sed -n '12457431, 12457440p' tomcat/logs/catalina.out

Linux tar 命令

发表于 2018-02-06 | 更新于 2022-06-02 | 分类于 Linux
| 字数: 340 | 时长 ≈ 1 分钟
标签 shell tar

tar

解压

1
tar -zxvf xxx.tar.gz

打包

1
tar -zcvf xxx.tar.gz 待压缩的文件名

解压 tar zxvf 文件名.tar.gz

压缩 tar zcvf 文件名.tar.gz 待压缩的文件名

tar -zcvf tomcat.tar.gz –exclude=.log –exclude=.log. –exclude=.out –exclude=.out. –exclude=.tgz.bak –exclude=.war tomcat/

排除文件夹(注意排除的文件夹最后不能加/)

tar -zcvf gitlab.source.tar.gz –exclude=node_modules –exclude=target gitlab/

Linux tail 命令

发表于 2018-02-06 | 更新于 2018-05-17 | 分类于 Linux
| 字数: 4 | 时长 ≈ 1 分钟
标签 shell tail

tail

Linux unzip 命令

发表于 2018-02-06 | 更新于 2021-01-13 | 分类于 Linux
| 字数: 61 | 时长 ≈ 1 分钟
标签 shell unzip

unzip

解压war、jar、zip、rar等文件

1
unzip -oq /opt/xxx.war -d /opt/ddd

Linux vi 命令

发表于 2018-02-06 | 更新于 2021-06-30 | 分类于 Linux
| 字数: 130 | 时长 ≈ 1 分钟
标签 shell vi

vi

linux文件格式的问题(使用unix格式)

1
2
3
4
5
6
7
8
9
# 查看文件格式
vi 文件名
:set ff # :set fileencoding
# 设置文件格式为unix
:set ff=unix
# 保存退出
:wq
# 也可以直接使用
dos2unix 文件名

Spring Data JPA 使用

发表于 2017-09-11 | 更新于 2021-04-12 | 分类于 Java
| 字数: 3.2k | 时长 ≈ 3 分钟
标签 spring-boot jpa hibernate

Spring Data JPA 常用注解

  1. @Entity

    标识实体类是JPA实体,告诉JPA在程序运行时生成实体类对应表

  2. @Table

    设置实体类在数据库所对应的表名

    1
    2
    3
    4
    5
    @Entity
    @Table(name = "t_user")
    public class User implements java.io.Serializable {
    private static final long serialVersionUID = 4579521515899728869L;
    }
阅读全文 »

spring boot 使用注意事项

发表于 2017-09-11 | 更新于 2021-04-09 | 分类于 Java
| 字数: 9.4k | 时长 ≈ 9 分钟
标签 spring-boot

兼容问题

spring-boot-starter-parent切换回1.5.2.RELEASE版本

因为1.5.4.RELEASE、1.5.5.RELEASE、1.5.6.RELEASE、1.5.7.RELEASE、2.0.0.M1、2.0.0.M2、2.0.0.M3都存在使用spring-boot-starter-data-redis时,会出现异常

java.lang.NoSuchMethodError: org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.<init>异常

请查看https://github.com/spring-projects/spring-boot/issues/9606

阅读全文 »
1…101112…14
forever杨

forever杨

开心又过一日,唔开心又过一日

202 文章
31 分类
175 标签
GitHub
友情链接
  • Tidy的个人博客
© 2024 forever杨 | 站点总字数: 706k