linux每日命令,Linux日常命令整理

一、查看磁盘使用情况

[root@jerrik gc]# df -h

文件系统 容量 已用 可用 已用% 挂载点

/dev/vda1 40G 3.9G 34G 11% /

devtmpfs 1.9G 0 1.9G 0% /dev

tmpfs 1.9G 716K 1.9G 1% /dev/shm

tmpfs 1.9G 280K 1.9G 1% /run

tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup

tmpfs 380M 0 380M 0% /run/user/0

二、查看根目录文件夹占用磁盘情况

[root@jerrik /]# du -sh *

0 bin

154M boot

716K dev

32M etc

19M home

0 lib

0 lib64

16K lost+found

2.9G usr

495M var

...

三、删除指定目录下的文件

find /usr/local/software/gc -name "*.log" -exec rm{} \;

find . -name "*.log"|xargs rm -rf {};

四、查看、创建定时任务(crontab)

创建定时任务:

crontab -e

进入vim

然后键入:

* * * * * check.sh

:wq保存即可

如果要查看定时任务是否执行,可以查看/var/log/cron中的执行日志.

查看定时任务:

[root@jerrik software]# crontab -l

* * * * * echo "hello world"

* * * * * /usr/local/software/demo.sh

[root@jerrik software]#

五、按照更新时间来查找文件

#查看最近2分钟之内没有更新的文件

find . -cmin +2

#查找文件更新时间在距现在二天以内的文件

find ./ -mtime -2

#查找文件更新时间距现在二天以上的文件

find ./ -mtime +2

六、后台执行命令

nohup [command] >/dev/null 2>&1 &

备注:

【/dev/null】: 是要把输出重定向到空设备上

【2>&1】: 把标准错误2重定向到标准输出中1中

【最后一个&】: 即后台运行

七、top查看系统负载

[root@jerrik software]# top

top - 23:27:35 up 130 days, 1:04, 1 user, load average: 0.00, 0.01, 0.05

Tasks: 70 total, 1 running, 69 sleeping, 0 stopped, 0 zombie

%Cpu(s): 0.0/0.0 0[ ]

KiB Mem : 3881920 total, 2087416 free, 350412 used, 1444092 buff/cache

KiB Swap: 0 total, 0 free, 0 used. 3237956 avail Mem

【大写P】:按CPU从高到低排序

【大写M】:按Memory从高到低排序

【数字1】:显示所有CPU

八、查看CPU型号

[root@jerrik software]# lscpu

Architecture: x86_64

CPU op-mode(s): 32-bit, 64-bit

Byte Order: Little Endian

CPU(s): 2

On-line CPU(s) list: 0,1

Thread(s) per core: 2

Core(s) per socket: 1

座: 1

NUMA 节点: 1

厂商 ID: GenuineIntel

CPU 系列: 6

型号: 85

型号名称: Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz

步进: 4

CPU MHz: 2499.996

BogoMIPS: 4999.99

超管理器厂商: KVM

虚拟化类型: 完全

L1d 缓存: 32K

L1i 缓存: 32K

L2 缓存: 1024K

L3 缓存: 33792K

NUMA 节点0 CPU: 0,1

九、查看物理CPU、逻辑CPU、CPU线程

#物理CPU

#说明只有一核

cat /proc/cpuinfo | grep "physical id"|sort|uniq

physical id : 0

#逻辑CPU

#说明单个CPU的逻辑核心数量是1个

cat /proc/cpuinfo | fgrep "cores"|uniq

cpu cores : 1

#查看CPU线程数

#系统CPU线程数为2

cat /proc/cpuinfo | grep "processor" | wc -l

2

备注:该CPU只有一个物理CPU,且该CPU只有一个逻辑核心,但是对应了2个CPU线程,所以该CPU启用了【超线程】技术。

十、dstat命令

dstat [-afv] [options..] [delay [count]]

-c:显示CPU系统占用,用户占用,空闲,等待,中断,软件中断等信息。

-C:当有多个CPU时候,此参数可按需分别显示cpu状态,例:-C 0,1 是显示cpu0和cpu1的信息。

-d:显示磁盘读写数据大小。

-D hda,total:include hda and total。

-n:显示网络状态。

-N eth1,total:有多块网卡时,指定要显示的网卡。

-l:显示系统负载情况。

-m:显示内存使用情况。

-g:显示页面使用情况。

-p:显示进程状态。

-s:显示交换分区使用情况。

-S:类似D/N。

-r:I/O请求情况。

-y:系统状态。

--ipc:显示ipc消息队列,信号等信息。

--socket:用来显示tcp udp端口状态。

-a:此为默认选项,等同于-cdngy。

-v:等同于 -pmgdsc -D total。

--output 文件:此选项也比较有用,可以把状态信息以csv的格式重定向到指定的文件中,以便日后查看.

#3秒钟监控一次,总共100次

dstat 3 100

[root@jerrik software]# dstat 3 1000

You did not select any stats, using -cdngy by default.

----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--

usr sys idl wai hiq siq| read writ| recv send| in out | int csw

0 0 99 0 0 0| 46B 3975B| 0 0 | 0 0 | 582 1149

0 0 99 0 0 0| 0 819B| 24B 40B| 0 0 | 224 448

...

#监控swap,process,sockets,filesystem并显示监控的时间

[root@iZ23uulau1tZ ~]# dstat -tsp --socket --fs

----system---- ----swap--- ---procs--- ------sockets------ --filesystem-

date/time | used free|run blk new|tot tcp udp raw frg|files inodes

26-07 09:23:48| 0 0 | 0 0 0.0|104 8 5 0 0| 704 6488

26-07 09:23:49| 0 0 | 0 0 0|104 8 5 0 0| 704 6488

26-07 09:23:50| 0 0 | 0 0 0|104 8 5 0 0| 704 6489

26-07 09:23:51| 0 0 | 0 0 0|104 8 5 0 0| 704 6489

26-07 09:23:52| 0 0 | 0 0 0|104 8 5 0 0| 704 6489

26-07 09:23:53| 0 0 | 0 0 0|104 8 5 0 0| 704 6489

十一、查看进程启动时间

ps -p [pid] -o lstart

十二、tcpdump抓包

#抓取所有经过 eth0,目的或源地址是 192.168.29.162 的网络数据

命令:tcpdump -n -i eth0 host 192.168.29.162

# 源地址

命令:tcpdump -i eth1 src host 192.168.29.162

# 目的地址

命令:tcpdump -i eth1 dst host 192.168.29.162

#抓取当前服务器eth0网卡端口8080的网络数据

命令:tcpdump -n -i eth0 port 8080

#抓取目标地址192.168.29.162端口8080的数据

命令:tcpdump -n -i eth0 dst host 192.168.29.162 and port 8080

#抓取mysql执行的sql语句

命令:tcpdump -i eth1 -s 0 -l -w - dst port 3306 | strings

#抓取mysql通讯的网络包(cap用wireshark打开)

命令tcpdump -n -nn -tttt -i eth0 -s 65535 'port 3306' -w 20181005mysql.cap

#抓取SMTP 数据

命令:tcpdump -i eth1 'tcp[tcpflags] & tcp-syn != 0 and tcp[tcpflags] & tcp-ack != 0'

#抓取HTTP GET数据,"GET "的十六进制是 47455420

命令:tcpdump -i eth1 'tcp[(tcp[12]>>2):4] = 0x47455420'

#抓取SSH返回,"SSH-"的十六进制是 0x5353482D

命令:tcpdump -i eth1 'tcp[(tcp[12]>>2):4] = 0x5353482D'

#实时抓取端口号8080的GET包,然后写入GET.log

命令:tcpdump -i eth0 '((port 8080) and (tcp[(tcp[12]>>2):4]=0x47455420))' -nnAl -w /tmp/GET.log

#抓取指定SYN个数,-c 参数指定抓多少个包。

命令:time tcpdump -nn -i eth0 'tcp[tcpflags] = tcp-syn' -c 10

十三、ethtool 查看机器带宽

[root@xxx]# ethtool eth1

Settings for eth1:

Supported ports: [ TP ]

Supported link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Full

Supports auto-negotiation: Yes

Advertised link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Full

Advertised pause frame use: Symmetric

Advertised auto-negotiation: Yes

Speed: 1000Mb/s

Duplex: Full

Port: Twisted Pair

PHYAD: 1

Transceiver: internal

Auto-negotiation: on

MDI-X: on

Supports Wake-on: pumbg

Wake-on: g

Current message level: 0x00000007 (7)

Link detected: yes

下面的speed代表的就是机器带宽。

总结

对一些常用的操作简单的总结了一下,由于时间的关系,今天就先到这里。以后会陆续进行补充,加深记忆。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值