练习题
第一题
[root@wzh ~]# grep 'nologin$' /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
nginx:x:998:996:Nginx web server:/var/lib/nginx:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
第二题
[root@wzh ~]# ifconfig|grep -w '10.0.0.200'|cut -d ' ' -f 10
10.0.0.200
第三题
[root@wzh ~]# cat /etc/sysconfig/selinux|sed 's#SELINUX=enforcing#SELINUX=disabled#g'
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
第四题
[root@wzh ~]# cat web.log|cut -d '/' -f3|sort|uniq -c
1 mp3.driverzeng.com
2 post.driverzeng.com
3 www.driverzeng.com
第五题
[wzh@wzh root]$ su wzh
Password:
su: Authentication failure
[wzh@wzh root]$ ^C
[wzh@wzh root]$
[wzh@wzh root]$
[wzh@wzh root]$ whoami
wzh
第六题
wzh@wzh ~]$ touch song{1..6}.mp3
[wzh@wzh ~]$ ll
total 0
-rw-rw-r--. 1 wzh wzh 0 Mar 24 02:06 song1.mp3
-rw-rw-r--. 1 wzh wzh 0 Mar 24 02:06 song2.mp3
-rw-rw-r--. 1 wzh wzh 0 Mar 24 02:06 song3.mp3
-rw-rw-r--. 1 wzh wzh 0 Mar 24 02:06 song4.mp3
-rw-rw-r--. 1 wzh wzh 0 Mar 24 02:06 song5.mp3
-rw-rw-r--. 1 wzh wzh 0 Mar 24 02:06 song6.mp3
第七题
[wzh@wzh ~]$ mv song{1..6}.mp3 Music
第八题
[wzh@wzh ~]$ mkdir friends family workl
[wzh@wzh ~]$ ll
第九题
[wzh@wzh friends]$ cp ../Music/song{1..3}.mp3 .
[wzh@wzh friends]$ ll
total 0
-rw-rw-r--. 1 wzh wzh 0 Mar 24 02:37 song1.mp3
-rw-rw-r--. 1 wzh wzh 0 Mar 24 02:37 song2.mp3
-rw-rw-r--. 1 wzh wzh 0 Mar 24 02:37 song3.mp3
第十题
[wzh@wzh family]$ mv ../Music/song{4,5,6}.mp3 .
[wzh@wzh family]$ ll
total 0
-rw-rw-r--. 1 wzh wzh 0 Mar 24 02:06 song4.mp3
-rw-rw-r--. 1 wzh wzh 0 Mar 24 02:06 song5.mp3
-rw-rw-r--. 1 wzh wzh 0 Mar 24 02:06 song6.mp3
十一题
cd
十二题
[wzh@wzh ~]$ rm -rf family
十三题
[wzh@wzh friends]$ rm -rf ./*
[wzh@wzh friends]$ ll
total 0
十四题
[wzh@wzh ~]$ rm -rf friends
文件查找命令
# 查找⽂件或⽬录locate
yum install -y mlocate
updatedb
[root@localhost opt]# locate /etc/sh
/etc/shadow
/etc/shadow-
/etc/shells
命令查找
[root@wzh wzh]# which cat
/usr/bin/cat
$():执⾏命令的结果
``:执⾏命令的结果
type -a
[root@wzh wzh]# type -a grep
grep is aliased to `grep --color=auto'
grep is /usr/bin/grep
[root@wzh wzh]# whereis cat
cat: /usr/bin/cat /usr/share/man/man1/cat.1.gz 命令路径查询
字符处理命令
sort
排序,默认以首字母顺序排序
-t:指定分隔符
-r:倒叙排序,从大到小
-n:以数字大小排序,从小到大
-k:指定按哪一列排序
/etc/passwd文件指定:分隔符以数值大小进行倒叙排序
[root@wzh wzh]# cat /etc/passwd|sort -t ':' -rnk3
wsh1:x:1002:1002::/home/wsh1:/bin/bash
wzh1:x:1001:1001::/home/wzh1:/bin/bash
wzh:x:1000:1000::/home/wzh:/bin/bash
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
nginx:x:998:996:Nginx web server:/var/lib/nginx:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
----
以冒号为分隔符取第三列从小到大排序
[root@wzh wzh]# cat /etc/passwd|sort -t ':' -nk3
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
把相同的数字放在一起
[root@wzh wzh]# cat 123.txt|sort
123
123
456
456789
456789
789
uniq 去重命令还可以统计重复几次
[root@wzh wzh]# cat 123.txt|sort|uniq
123
456
456789
789
统计重复次数
[root@wzh wzh]# cat 123.txt|sort|uniq -c
2 123
1 456
2 456789
1 789
字符截取命令
cut
-d:指定分隔符
-f:指定区域
-c:按照字符截取
以冒号为分隔符取第三列
[root@wzh wzh]# cat /etc/passwd|cut -d ':' -f3
以冒号为分隔符取第三,五,六列
[root@wzh wzh]# cat /etc/passwd|cut -d ':' -f3,5,6
取字符
[root@wzh wzh]# cat /etc/passwd|cut -c 2,3,4,5,6,7,8,9
oot:x:0:
in:x:1:1
aemon:x:
dm:x:3:4
p:x:4:7:
ync:x:5:
hutdown:
alt:x:7:
ail:x:8:
字符替换命令
把2替换成空格
[root@wzh wzh]# cat 123.txt|tr '2' ' '
1 3
456789
1 3
统计命令
-l:统计行数
-c:统计字符
-w:统计单词
统计/etc/services文件行数
[root@wzh wzh]# less /etc/services|wc -l
11176
统计/etc/services文件单词
[root@wzh wzh]# less /etc/services|wc -w
61033
统计/etc/services文件有多少字符
[root@wzh wzh]# less /etc/services|wc -c
670293