linux下常用的一下命令 工作中我们会经常遇到各种各样的问题,遇到我们解决不了的我们会查找相关的资料,下面就是我平时工作中遇到的一些场景,记录的一些关于linux下操作的相关命令,希望对大家有用,会不定时更新~
nmcli 命令 1 2 3 4 5 6 7 # 查看连接状态 nmcli connection show # 查看网络设备,包括物理网卡和虚拟网卡。 # 通过nmcli device 查看当前的网卡设备,其中CONNECTION 中有内容的是代表当前网卡处于活跃状态 nmcli device nmcli dev
firewalld防火墙 1 2 3 4 5 6 7 8 9 10 11 firewall-cmd --zone=public --add-port=4400-4600/udp --permanent(指定端口范围为4400-4600通过防火墙) 其中: --zone --add-port=80/tcp --permanent firewall-cmd --zone=public --remove-port=80/tcp --permanent(关闭指定端口) firewall-cmd --zone=public --list-ports(查看通过的端口) firewall-cmd --state
iptables 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 1、iptables -L 2、iptables -L [-t 表名] 3、iptables -L [-t 表名] [链名] 4、iptables -n -L 5、iptables -nv -L iptables -D INPUT -s 192.168.1.5 -j DROP iptables -nL --line-number iptables -D INPUT 2
[1] https://blog.csdn.net/chengxuyuanyonghu/article/details/51897666
find 查找命令 1 2 3 4 5 6 find / -name test.cpp -exec ls -l {} \; {} 代表的是find找到的内容,find的结果会被放置到{}位置中。 -exec 一直到\;是关键字,代表的是find额外的动作开始(-exec )到结束(;\)。 因为在bash环境下’;‘符号是有特殊意义的,因此用反斜杠'\\' 来跳脱。
tcpreplay 命令 1 2 3 4 # 先安装"epel-release" 的软件包 yum install epel-release # 安装tcpreplay软件包 yum install tcpreplay
ps命令
tar 压缩、解压命令 1 2 3 4 5 6 7 tar -zcvf /tmp/etc.tar.gz /etc tar -cvf /home/abc.tar /home/abc tar -zcvf /home/abc.tar.gz /home/abc tar -zxvf /tmp/etc.tar.gz
systemctl 命令 1 2 3 4 5 # 需要锁定该服务时执行 systemctl mask firewalld # 实现取消服务的锁定 systemctl unmask firewalld
systemd 服务 1 2 3 4 5 6 7 8 9 # systemd 添加使用环境变量的方法 Environment="One=1" "Two=2" Environment="Three=3" # 使用文件file的方式 EnvironmentFile=/usr/local/env_test/load.conf file内容如下: MY_ENV="helloworld" GLOBAL_ENV="nihaoshijie"
[1] https://www.jibing57.com/2022/10/09/environment-varilables-in-systemd-service/
路由配置相关 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 ip -6 addr add <ipv6address>/<prefixlength> dev <interface> ip -6 addr add 2001:0db8:0:f101::1/64 dev eth0 ifconfig <interface> inet6 add <ipv6address>/<prefixlength> ifconfig eth0 inet6 add 2001:0db8:0:f101::1/64 ip -6 route add <ipv6network>/<prefixlength> via <ipv6address> ip -6 route add default via 2001:0db8:0:f101::1 route -A inet6 add <ipv6network>/<prefixlength> gw route -A inet6 add default gw 2001:0db8:0:f101::1 ip -6 route show route -A 'inet6' route -6 route print ip -6 neighbor show netsh interface ipv6 show neighbors ping smtp.sohu.com ping smtp.qq.com
更新内核命令
大文件重定向有效信息 1 2 grep -C 2000 ‘Call Trace’ dmesg.txt >nn.txt
Shell递归删除指定字符串文件或者目录 1 2 3 4 # 文件 find . -name "*.rej" | xargs rm -rf # 目录 find . -type d -name "*.rej" | xargs rm -rf
文件夹建立软链接(用绝对地址) 1 2 ln -s 源地址 目的地址 ln -s /opt/linux/rootfs_dir /home/jyg/rootfs_dir
大数据报文件分割 1 2 3 4 5 windows下 d:>wireshark>editcap -C 1000000(文件大小) 待分割文件路径 新文件名称 linux 可使用split 命令
ps查看进程存活时间 1 2 ps -eo pid,lstart,etime|grep pid
CPU相关 1 2 3 4 5 6 7 8 9 10 11 cat /proc/cpuinfo |grep "physical id" |sort |uniq |wc -lcat /proc/cpuinfo |grep "processor" |wc -lcat /proc/cpuinfo |grep "cores" |uniq cat /proc/cpuinfo |grep MHz|uniq
watch 实时监控 1 2 3 4 5 watch -n 1 'cat /proc/loadavg' watch -n 1 -d 'pstree|grep http'
rpm 命令 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 rpm -qpR [package] rpm -qR centos-release rpm -qpR centos-release 或 yum deplist centos-release rpm -ivh [package] rpm -qa|grep gdb rpm -e --test centos-release 错误:依赖检测失败: rpcbind 被 (已安裝) quota -1:4.01-17.el7.x86_64 需要 rpmbuild --showrc|grep buildroot rpmbuild -ba SPEC/starpath.spec rpm --eval "%{_bindir}" rpm -qpi starpath-1.0.0-121.el8.x86_64.rpm rpminfo starpath-1.0.0-121.el8.x86_64.rpm rpm -qpi starpath-1.0.0-121.el8.x86_64.rpm --changelog|more rpm2cpio xxx.rpm | cpio -div rpm --scripts -qp ./nginx-1.12.2-2.el7.x86_64.rpm rpm -ql ./nginx-1.12.2-2.el7.x86_64.rpm [hadoop@localhost ~]$ rpm -qf /usr/lib filesystem-3.2-25.el7.x86_64 rpm -ivh rpm包全名 -i(install) -v(verbose) -h(hash ) --test --nodeps --replacepkgs --nosignature --nodigest --noscripts %pre:安装前脚本; --nopre %post:安装后脚本; --nopost %preun:卸载前脚本; --nopreun rpm包如果制作不当,可能在卸载时产生各种问题导致无法正常卸载。 error: %preun()scriptlet failed,exit status 1 表示rpm的 %preun段部分的脚本执行有问题,返回码为1,此时rpm卸载动作会中止,如果想要强制卸载,可以用选项参数 rpm -e xxx--nopreun 类似的,%postun %pre %post等这些段落中的脚本也可能出现问题,相对应的可以用 -nopostun -nopre -nopost 这些选项来忽略错误,让安装或卸载继续执行。 另外,-noscripts 相当于-nopre-nopost-nopreun-nopostun。即跳过这4个段落里所有的脚本执行。 当出现error::specifies multiple packages错误时,说明因为rpm安装或制作不当,出现了两个不同版本的同名软件,此时卸载无 法正常执行,如果需要把这两个都卸载,则用-allmatches选项即可。 https://pkgs.org/
[1] https://blog.51cto.com/chouketsu/1569607
Linux 删除乱码文件 1 2 3 4 5 ls -ilfind -inum 203179434 -exec rm {} -rf \
mount 挂载文件系统 1 2 mount -n -o remount,rw /
ftp 命令 1 2 3 4 5 6 7 8 binary lcd mput D:\User\Desktop\Desktop\*
CPU 相关 1 2 3 # 设置某个进程运行在某个cpu上 taskset -p pid taskset -pc 0 pid
udvadm 命令 1 2 # 查找指定设备的属性信息 udevadm info --query=all --name=/dev/sdb
ldconfig 命令 1 2 3 4 5 6 7 8 9 # 管理及查看本机装载的库文件 ldconfig 加载库文件 /sbin/ldconfig -p: 显示本机已经缓存的所有可用库文件名及文件路径映射关系 # 配置文件 /etc/ld.so.conf, /etc/ld.so.conf.d/*.conf # 缓存文件 /etc/ld.so.cache
nm 命令 1 2 3 4 5 6 7 8 9 10 11 12 13 nm 命令用于列出共享库或可执行文件中的符号信息,包括函数、变量等。符号前面的字母标识了符号的类型,T 和 t 是两种可能的符号类型。 T 符号: T 符号通常代表全局符号,是全局可见的函数或变量。 这些符号在编译时被定义,可以在程序内的任何地方访问。 一般来说,T 符号表示公共的函数或变量。 t 符号: t 符号通常代表局部符号,只在定义它们的编译单元(通常是源代码文件)中可见。 这些符号通常是静态函数或变量,只能在定义它们的编译单元内访问。 t 符号通常是局部的、内部使用的函数或变量,不对外可见。 总之,T 符号表示全局可见的符号,可以被其他编译单元或程序访问,而 t 符号表示局部符号,只能在定义它们的编译单元内可见。符号的可见性和范围由编译器和链接器处理,nm 命令的输出用于显示这些符号的信息,以便进行调试和分析。