linux 常用命令

linux 命令大全

其他命令

1
2
3
top

free -h

curl

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
# 下载 -o 文件名;-O默认文件名保存
curl -o baidu.hml http://www.baidu.com
curl -O http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png
curl -O http://121.199.28.164/llc/resource/img/jidihaiyang0[1-2].jpg

# -x proxy代理
curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com

# -D 写入header到cookie0001.txt文件
curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com

# -b 引用本地cookie0001.txt,发送请求
curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com

# -d 发送http的post请求
curl -d "cmd=login&username=loganv&password=123456&vcode=1234" -D cookie001.txt http://www.linuxidc.com/ajax.aspx

# -F 表单提交,post上传文件可用@localfilepath
curl -F upload=@123.txt -F nick=loganv http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi

# -T 上传本地文件到ftp服务器 -u una:pwd
curl -T 123.txt -u qxu1606420111:ftpftp123 ftp://qxu1606420111.my3w.com/myfolder/a.txt

# -A 模拟请求浏览器
# avascript:alert(window.navigator.userAgent);
curl -A "Mozilla/5.0 (iPod touch; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B411 Safari/600.1.4" -o baidu.html -D cookie0001.txt http://www.baidu.com

# -I 仅返回header
# -H "Connection: keep-alive \n Content-Type: text/html" 设置 header

scp

1
2
3
4
5
6
7
8
# 本地-->远程
scp ~/Desktop/1.txt root@192.168.0.1:~/Downloads/

# 远程-->本地
scp root@192.168.0.1:~/Downloads/1.txt ~/Desktop/1.txt

# scp -i 证书路径 源文件路径 拷贝路径
# 端口大P: -P 51022

pgrep

1
2
查看进程ID
pgrep mysqld

ps

参考

1
2
3
4
5
6
7
8
9
10
ps -aux|grep nginx
# 或
ps -aux|grep nginx
# 按 rss 排序
ps -aux --sort -rss

# 批量杀掉查询出来的kamailio所有进程
pgrep kamailio | xargs kill -s 9
# 或
killall kamailio

lsof

1
2
3
4
lsof -i tcp:8080

# 查看 进程的执行信息,PID为对应的进程ID
# ls -al /proc/PID

netstat

查看端口

1
2
3
4
5
netstat -apn|grep nginx
# 或
netstat -nutlp|grep 80
# 所有端口
netstat -apn

nohup

挂起 xx.sh,日志、错误输出到 xx.log 文件

1
nohup xx.sh > xx.log 2>&1 &

chmod

1
2
3
4
5
6
7
8
9
# 权限组成 all[user|group|other]
# -R 递归子文件夹里面所有文件,[-cfv]
# chmod [ugoa][+-=][rwxX] file
chmod a=rwx file
chmod g-w file
chmod go+x file

# 权限三位数字对应于[ugo],权限数值(可相加) r = 4, w = 2, x = 1
chmod 750 file

chown

1
2
3
# -R 递归子文件夹里面所有文件,
# 设置file文件的所属组为groupname,所属用户username
chown groupname:username file

jobs

1
2
3
4
5
6
7
8
9
10
11
#显示所有后台进程: 编号(%n),pid
jobs -l

#把后台进程,调到前台运行
fg %n

#让后台的进程,继续执行
bg %n

#正在运行的进程调到后台挂起
crtl+z

查看系统版本

1
2
3
4
5
6
7
8
9
uname -a
# 或
cat /proc/version
# 或
cat /etc/issue
# 或
cat /proc/cpuinfo
# 或
lsb_release -a

环境变量

1
2
3
4
5
6
7
8
9
10
export PATH="$PATH:`pwd`/flutter/bin"



# 编辑 ~/.bash_profile
vi /etc/profile
# 查看
export ECS_LLC="loganv"
# 使修改立马生效
source /etc/profile

tar

1
2
3
4
# 压缩
tar -zcvf xx.tar.gz xx_folder
# 解压
tar -zxvf xx.tar.gz

crontab

启动定时任务

1
2
3
service crond start
# 或
/sbin/service crond start

编辑、查看、删除

1
crontabl [-e|-l|-r]

查看配置语法

1
/etc/crontab

取值范围

分钟 小时
00-59 00-23 01-31 01-12 0-6 (0 is sunday)
  • * 对应值的所有范围
  • / 频率(比如,*/10 在minute位置,匹配:每10分钟 )
  • , 表示自定义选值范围(比如,6,18 在hour位置,匹配:6点、18点)
  • - 表示连续选择范围(比如,9-12 在day位置,匹配:9号、10号、11号、12号)

例如

1
*/10 6,18 9-12 * * /usr/loganv/daka.sh

注意每个范围的时间周期,需要空格隔开


make

1
2
3
4
5
make install
make clean: 清除已编译的二进制文件(Binaries)和对象文件(Object)
make distclean: 彻底清除,清除包括配置文件在内
make install: 将编译出的可执行文件安装到系统,需要root权限
make uninstall: 从系统中卸载,也需要root权限

iptables 简单用法

参考

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 编辑
vi /etc/sysconfig/iptables
# 修改完之后要 save,然后在 restart,才能生效

# 加入允许的端口
-A INPUT -s 218.106.118.0/24 -p tcp -m multiport --dports 51022 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 80,443,3000,3200,3330,3690,6379 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 7000:7100 -j ACCEPT

# -A: INPUT|OUTPUT 规则
# -p: tcp|udp 协议
# --dport 目的端口
# --sport 来源端口
# -j: ACCEPT|DROP 是否接受
# -s 来源的IP

# 查看iptables
iptables -L -n

# 命令(/etc/init.d/iptables)
service iptables