[root@bogon ~]# cat -n /etc/issue > test.txt ##查看文件内容并显示行号,重定向到test.txt文件中 [root@bogon ~]# cat test.txt 1 \S 2 Kernel \r on an \m 3 [root@bogon ~]# cat > file <<EOF ##创建file文件,输入内容以EOF结束 > kernel \r on an \m > EOF [root@bogon ~]# cat file kernel \r on an \m
[root@bogon ~]# head -5 /etc/fstab ##显示文件前5行 # # /etc/fstab # Created by anaconda on Mon May 1 04:49:06 2017 # [root@bogon ~]# head -q -n 5 /etc/fstab /etc/issue ##显示多个文件前5行,并且不显示文件头 # # /etc/fstab # Created by anaconda on Mon May 1 04:49:06 2017 # \S Kernel \r on an \m
[root@bogon ~]# tail -2 /etc/passwd ##显示文件后2行 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin [root@bogon ~]# tail -f /var/log/messages ##不停地去读最新的内容,有实时监视的效果,用Ctrl+c来终止 May 2 02:46:26 localhost systemd: Configuration file /usr/lib/systemd/system/wpa_supplicant.service is marked executable. Please remove executable permission bits. Proceeding anyway. May 2 02:46:26 localhost yum[16325]: Installed: httpd-2.4.6-45.el7.centos.4.x86_64 May 2 03:01:01 localhost systemd: Started Session 10 of user root. May 2 03:01:01 localhost systemd: Starting Session 10 of user root. May 2 03:45:49 localhost systemd-logind: Removed session 4. May 2 03:46:20 localhost systemd: Started Session 11 of user root. May 2 03:46:20 localhost systemd-logind: New session 11 of user root. May 2 03:46:20 localhost systemd: Starting Session 11 of user root. May 2 04:01:01 localhost systemd: Started Session 12 of user root. May 2 04:01:01 localhost systemd: Starting Session 12 of user root.
[root@bogon ~]# head /etc/passwd |cut -d ":" -f1,7 --output-delimiter=" " ##查看系统用户使用的shell root /bin/bash bin /sbin/nologin daemon /sbin/nologin adm /sbin/nologin lp /sbin/nologin sync /bin/sync shutdown /sbin/shutdown halt /sbin/halt mail /sbin/nologin operator /sbin/nologin [root@bogon ~]# ip addr |tail -4 |head -1 |cut -d "/" -f1 |cut -d " " -f6 ##获取ip地址 192.168.25.102
[root@bogon ~]# paste /etc/resolv.conf /etc/issue ##合并输出两个文件的内容 # Generated by NetworkManager \S nameserver 202.106.46.151 Kernel \r on an \m nameserver 202.106.195.68 [root@bogon ~]# paste -s /etc/issue ##对输出的内容独立占一行 \S Kernel \r on an \m
[root@bogon ~]# cat /etc/passwd |wc -l ##统计文件的行数 22 [root@bogon ~]# echo "aaa bbb ccc" |wc -w ##统计输出的单词数量 3 [root@bogon ~]# echo "abcdef" |wc -m ##统计输出有多少个字节 7
[root@bogon ~]# head /etc/passwd |sort -t ":" -k 3nr ##以“:”分割对第三个字段数值进行倒序排列 operator:x:11:0:operator:/root:/sbin/nologin mail:x:8:12:mail:/var/spool/mail:/sbin/nologin halt:x:7:0:halt:/sbin:/sbin/halt shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown sync:x:5:0:sync:/sbin:/bin/sync lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin bin:x:1:1:bin:/bin:/sbin/nologin root:x:0:0:root:/root:/bin/bash [root@bogon ~]# cat /etc/passwd |sort -t':' -k 7 -u ##以“:”分割对第7个字段排序,去重 root:x:0:0:root:/root:/bin/bash sync:x:5:0:sync:/sbin:/bin/sync halt:x:7:0:halt:/sbin:/sbin/halt bin:x:1:1:bin:/bin:/sbin/nologin shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
[root@bogon ~]# uniq -c ip.txt ##显示重复行出现的次数,相邻行且完全一样为重复 3 101.200.78.99 1 103.41.52.94 2 106.185.47.161 1 101.200.78.99 2 113.240.250.155 1 13.0.782.215 1 185.130.5.231
[root@bogon ~]# diff file1.txt file2.txt 8c8 ##表示第8行有区别 < 113.240.250.155 --- > 133.240.250.155
[root@bogon ~]# tr -s '\n' < file1.txt ##删除空行 103.41.52.94 106.185.47.161 \S Kernel \r on an \m 106.185.47.161 [root@bogon ~]# tr A-Z a-z < file1.txt ##把大写字母换成小写 103.41.52.94 106.185.47.161 \s kernel \r on an \m 106.185.47.161
[root@bogon ~]# grep '^\(root\|apache\)' test.txt ##过滤以root或apache开头的行
root:x:0:0:root:/root:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
[root@bogon ~]# grep -R /sbin/nologin * ##递归从所以文件中查询匹配的内容
test.txt:bin:x:1:1:bin:/bin:/sbin/nologin
test.txt:daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@bogon ~]# ip addr |grep "dynamic" |tr -s " " |cut -d " " -f3 |cut -d "/" -f1 ##过滤ip地址
192.168.25.102
[root@bogon ~]# ip addr |grep -E -o "([0-9]{1,3}[\.]){1,3}[0-9]{1,3}"
127.0.0.1
192.168.25.102
192.168.25.255
[root@bogon ~]# df -Th |tr -s " " |sort -k 6nr |head -1 ##查出使用率的最大百分比值的分区
/dev/sda1 xfs 497M 125M 373M 25% /boot
[root@bogon ~]# cat /etc/passwd |sort -t ':' -k 3n |tail -1 |cut -d ":" -f1,3,7
systemd-bus-proxy:999:/sbin/nologin ##找出uid最大值的用户,并显示用户名、UID、及shell类型
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有