第一阶段练习题

张开发
2026/4/19 1:31:26 15 分钟阅读

分享文章

第一阶段练习题
一、系统信息与基础操作查看本机内核版本、主机名并永久修改主机名为 rhcsa-study[rootlocalhost ~]# uname -r 6.12.0-55.9.1.el10_0.x86_64 ​ [rootlocalhost ~]# hostname -s localhost ​ ​ [rootlocalhost ~]# hostnamectl hostname rchsa-study [rootlocalhost ~]# exit ... [rootrchsa-study ~]#查看系统所有可用 Shell并确认当前正在使用的 Shell[rootrchsa-study ~]# cat /etc/shells /bin/sh /bin/bash /usr/bin/sh /usr/bin/bash ​ ​把系统时区设为 Asia/Shanghai并将系统时间手动改为 2026-04-07 09:00:00[rootrchsa-study ~]# timedatectl set-ntp no [rootrchsa-study ~]# timedatectl set-timezone Asia/Shanghai [rootrchsa-study ~]# date -s 2026-04-07 09:00:00 2026年 04月 07日 星期二 09:00:00 CST用一条命令显示当前时间格式为年 - 月 - 日 时分: 秒[rootrchsa-study ~]# timedatectl set-ntp true [rootrchsa-study ~]# date %F%T 2026-04-0819:13:12二、目录与文件管理在 /root 下创建目录 test并在其中递归创建 a/b/c/d 四级目录[rootrchsa-study ~]# mkdir -pv /root/test/a/b/c/d mkdir: 已创建目录 /root/test/a mkdir: 已创建目录 /root/test/a/b mkdir: 已创建目录 /root/test/a/b/c mkdir: 已创建目录 /root/test/a/b/c/d在 /root/test 下批量创建 file1 到 file50 共 50 个普通文件[rootrchsa-study test]# touch file{1..50}查看 /root 目录本身的详细信息不显示里面内容[rootrchsa-study ~]# ls -d递归显示 /root/test/a 下所有层级文件[rootrchsa-study a]# ls -R .: b ​ ./b: c ​ ./b/c: d ​ ./b/c/d:把 /root/test/file10 复制到 /root/test/a/b/ 并改名为 test.txt[rootrchsa-study test]# cp file10 ./a/b/ [rootrchsa-study test]# cd ./a/b [rootrchsa-study b]# mv file10 test.txt强制删除 /root/test/file30 到 file40[rootrchsa-study test]# rm -f file{30..40}三、软硬链接实操在 /root 创建文件 note.txt写入内容 I love Linux[rootrchsa-study ~]# touch note.txt [rootrchsa-study ~]# echo I love Linux note.txt [rootrchsa-study ~]# cat note.txt I love Linux为 note.txt 在 / 下创建软链接 note.lnk[rootrchsa-study /]# ln -s /root/note.txt /note.lnk [rootrchsa-study /]# cat note.lnk I love Linux为 note.txt 在 /tmp 下创建硬链接 note.bak[rootrchsa-study ~]# ln /root/note.txt /tmp/note.bak [rootrchsa-study ~]# cat /tmp/note.bak I love Linux查看三个文件的 inode 号说明软硬链接区别[rootrchsa-study ~]# ll -i note.txt 67609608 -rw-r--r--. 3 root root 13 4月 8日 19:48 note.txt [rootrchsa-study ~]# ll -i /note.lnk 2183043 lrwxrwxrwx. 1 root root 14 4月 8日 20:04 /note.lnk - /root/note.txt [rootrchsa-study ~]# ll -i /tmp/note.bak 67609608 -rw-r--r--. 3 root root 13 4月 8日 19:48 /tmp/note.bak硬链接inode号与源文件相同 软链接与源文件不相同四、文本查看与 Vim 操作查看 /etc/passwd 的前 8 行、后 5 行[rootrchsa-study /]# head -8 /etc/passwd root:x:0:0:Super User:/root:/bin/bash bin:x:1:1:bin:/bin:/usr/sbin/nologin daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin adm:x:3:4:adm:/var/adm:/usr/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/usr/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt ​ ​ [rootrchsa-study /]# tail -5 /etc/passwd sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/usr/sbin/nologin chrony:x:982:981:chrony system user:/var/lib/chrony:/sbin/nologin dnsmasq:x:981:980:Dnsmasq DHCP and DNS server:/var/lib/dnsmasq:/usr/sbin/nologin tcpdump:x:72:72:tcpdump:/:/usr/sbin/nologin redhet:x:1000:1000:redhet:/home/redhet:/bin/bash用 cat 显示 /etc/passwd 并带行号[rootrchsa-study /]# cat -n /etc/passwd用 Vim 打开 /root/note.txt完成复制全文到末尾末行模式好一点 :1,2(开始行结束行) co 2(复制到第几行后)给所有行加 # 注释ctrlv 可视块:% s/^(要匹配的位置)/#(替换的字符)/删除所有空行:g /^$/d保存退出五、重定向、管道与文本处理把 ls / 的结果输出到 /root/list.txt[rootrchsa-study /]# ls /root/list.txt把 echo RHCSA 2026 追加到 /root/list.txt[rootrchsa-study /]# echo RHCSA 2026 /root/list.txt统计 /etc/passwd 一共有多少行即多少用户[rootrchsa-study /]# wc /etc/passwd 39 97 2355 /etc/passwd截取 /etc/passwd 中 第一个字段用户名 并输出[rootrchsa-study /]# cut -d : -f1 /etc/passwd过滤出 /etc/passwd 中包含 root 的所有行[rootrchsa-study /]# grep root /etc/passwd root:x:0:0:Super User:/root:/bin/bash operator:x:11:0:operator:/root:/usr/sbin/nologin六、查找、压缩与用户及别名查找系统中所有 .log 结尾且小于 100k 的文件[rootrchsa-study /]# find . -name *.log -size -100k把 /root/test 打包压缩为 linux_test.tar.gz[rootrchsa-study ~]# tar -czf linux_test.tar.gz test创建组 itgroup创建用户 tom 并加入该组为附加组[rootrchsa-study ~]# groupadd itgroup [rootrchsa-study ~]# useradd tom [rootrchsa-study ~]# usermod -G itgroup tom编辑系统级别所有用户永久生效的别名 cclear[rootrchsa-study ~]# vim /etc/bashrc[rootrchsa-study ~]# source /etc/bashrc [rootrchsa-study ~]# c编辑仅对你其中一个普通用户永久生效的别名 pingping -c3[rootrchsa-study ~]# vim /home/tom/.bashrc[rootrchsa-study ~]# vim /home/tom/.bashrc [rootrchsa-study ~]# su - tom [tomrchsa-study ~]$ alias ping alias pingping-c3 [tomrchsa-study ~]$

更多文章