知识检测2

张开发
2026/4/19 15:19:13 15 分钟阅读

分享文章

知识检测2
一、系统信息与基础操作查看本机内核版本、主机名并永久修改主机名为 rhcsa-study[rootlocalhost ~]# uname -r [rootlocalhost ~]# hostname [rootlocalhost ~]# echo rhcsa-study /etc/hostname ​查看系统所有可用 Shell并确认当前正在使用的 Shell[rootrhcsa-study ~]# cat /etc/shells /bin/sh /bin/bash /usr/bin/sh /usr/bin/bash [rootrhcsa-study ~]# echo $SHELL /bin/bash ​把系统时区设为 Asia/Shanghai并将系统时间手动改为 2026-04-07 09:00:00[rootrhcsa-study ~]# timedatectl set-timezone Asia/Shanghai [rootrhcsa-study ~]# timedatectl set-time 2026-04-07 [rootrhcsa-study ~]# timedatectl set-time 900用一条命令显示当前时间格式为年 - 月 - 日 时分: 秒[rootrhcsa-study ~]# date %Y-%m-%d %H:%M:%S二、目录与文件管理在 /root 下创建目录 test并在其中递归创建 a/b/c/d 四级目录[rootrhcsa-study ~]# mkdir -p /root/text/a/b/c/d ​在 /root/test 下批量创建 file1 到 file50 共 50 个普通文件[rootrhcsa-study ~]# touch /root/text/file{1..50} ​查看 /root 目录本身的详细信息不显示里面内容[rootrhcsa-study ~]# ls -dl dr-xr-x---. 6 root root 4096 4月 7日 09:13递归显示 /root/test/a 下所有层级文件[rootrhcsa-study ~]# ls -R /root/text/a /root/text/a: b ​ /root/text/a/b: c ​ /root/text/a/b/c: d ​ /root/text/a/b/c/d: ​把 /root/test/file10 复制到 /root/test/a/b/ 并改名为 test.txt[rootrhcsa-study ~]# cp /root/text/file10 /root/text/a/b/text.txt [rootrhcsa-study ~]# ll /root/text/a/b 总计 0 drwxr-xr-x. 3 root root 15 4月 7日 09:07 c -rw-r--r--. 1 root root 0 4月 7日 09:24 text.txt ​强制删除 /root/test/file30 到 file40[rootrhcsa-study ~]# rm -f /root/text/file{30..40} [rootrhcsa-study ~]# ll /root/text ​三、软硬链接实操在 /root 创建文件 note.txt写入内容 I love Linux[rootrhcsa-study ~]# echo I love Linux /root/note.txt [rootrhcsa-study ~]# cat /root/note.txt I love Linux ​为 note.txt 在 / 下创建软链接 note.lnk[rootrhcsa-study ~]# ln -s note.txt note.lnk [rootrhcsa-study ~]# ll note.lnk ​为 note.txt 在 /tmp 下创建硬链接 note.bak[rootrhcsa-study ~]# ln -s note.txt note.lnk查看三个文件的 inode 号说明软硬链接区别[rootrhcsa-study ~]# ls -li /root/note.txt /tmp/note.bak四、文本查看与 Vim 操作查看 /etc/passwd 的前 8 行、后 5 行[rootrhcsa-study ~]# head -n 8 /etc/passwd [rootrhcsa-study ~]# tail -n 5 /etc/passwd用 cat 显示 /etc/passwd 并带行号[rootrhcsa-study ~]# cat -n /etc/passwd用 Vim 打开 /root/note.txt完成​复制全文到末尾gg yG G p给所有行加 # 注释:%s/^/# /g删除所有空行:g/^$/d保存退出:wq五、重定向、管道与文本处理把 ls / 的结果输出到 /root/list.txt[rootrhcsa-study ~]# ls / /root/list.txt ​把 echo RHCSA 2026 追加到 /root/list.txt[rootrhcsa-study ~]# echo RHCSA 2026 /root/list.txt统计 /etc/passwd 一共有多少行即多少用户[rootrhcsa-study ~]# wc -l /etc/passwd截取 /etc/passwd 中 第一个字段用户名 并输出[rootrhcsa-study ~]# cut -d: -f1 /etc/passwd ​过滤出 /etc/passwd 中包含 root 的所有行[rootrhcsa-study ~]# grep root /etc/passwd六、查找、压缩与用户及别名查找系统中所有 .log 结尾且小于 100k 的文件[rootrhcsa-study ~]#find / -name *.log -size -100k把 /root/test 打包压缩为 linux_test.tar.gz[rootrhcsa-study ~]#tar -zcvf /root/linux_test.tar.gz /root/test创建组 itgroup创建用户 tom 并加入该组为附加组[rootrhcsa-study ~]#groupadd itgroup [rootrhcsa-study ~]#useradd -G itgroup tom编辑系统级别所有用户永久生效的别名 cclear[rootrhcsa-study ~]#echo alias cclear /etc/bashrc ​编辑仅对你其中一个普通用户永久生效的别名 pingping -c3[rootrhcsa-study ~]#echo alias pingping -c3 /home/tom/.bashrc

更多文章