作业 2.0

张开发
2026/4/11 5:02:17 15 分钟阅读

分享文章

作业 2.0
一、系统信息与基础操作查看本机内核版本、主机名并永久修改主机名为 rhcsa-study[rootlocalhost ~]# uname -r 6.12.0-55.9.1.el10_0.x86_64 [rootlocalhost ~]# hostname localhost.localdomain [rootlocalhost ~]# hostnamectl set-hostname chcsa-study ​查看系统所有可用 Shell并确认当前正在使用的 Shell[rootchcsa-study ~]# cat /etc/shells /bin/sh /bin/bash /usr/bin/sh /usr/bin/bash [rootchcsa-study ~]# echo $SHELL /bin/bash ​把系统时区设为 Asia/Shanghai并将系统时间手动改为 2026-04-07 09:00:00[rootchcsa-study ~]# timedatectl set-timezone Asia/Shanghai [rootchcsa-study ~]# timedatectl set-ntp no [rootchcsa-study ~]# timedatectl set-time 2026-04-07 [rootchcsa-study ~]# timedatectl set-time 09:00:00 [rootchcsa-study ~]# timedatectl Local time: 二 2026-04-07 09:00:06 CST Universal time: 二 2026-04-07 01:00:06 UTC RTC time: 二 2026-04-07 01:00:06 Time zone: Asia/Shanghai (CST, 0800) System clock synchronized: no NTP service: inactive RTC in local TZ: no ​用一条命令显示当前时间格式为年 - 月 - 日 时分: 秒[rootchcsa-study ~]# date %Y-%m-%d %H:%M:%S 2026-04-07 09:04:37 ​二、目录与文件管理在 /root 下创建目录 test并在其中递归创建 a/b/c/d 四级目录[rootchcsa-study ~]# mkdir -p /root/test/a/b/c/d [rootchcsa-study ~]# tree /root/test /root/test └── a └── b └── c └── d ​ 5 directories, 0 files ​在 /root/test 下批量创建 file1 到 file50 共 50 个普通文件[rootchcsa-study ~]# touch /root/test/file{1..50} ​查看 /root 目录本身的详细信息不显示里面内容[rootchcsa-study ~]# ls -dl /root dr-xr-x---. 16 root root 4096 4月 7日 09:07 /root ​递归显示 /root/test/a 下所有层级文件[rootchcsa-study ~]# ls -R /root/test/a /root/test/a: b ​ /root/test/a/b: c ​ /root/test/a/b/c: d ​ /root/test/a/b/c/d: ​把 /root/test/file10 复制到 /root/test/a/b/ 并改名为 test.txt[rootchcsa-study ~]# cp /root/test/file10 /root/test/a/b/test.txt [rootchcsa-study ~]# ls /root/test/a/b c file10 test.txt ​强制删除 /root/test/file30 到 file40[rootchcsa-study ~]# rm -f /root/test/file{30..40} ​三、软硬链接实操在 /root 创建文件 note.txt写入内容 I love Linux[rootchcsa-study ~]# echo I love Linux /root/note.txt [rootchcsa-study ~]# cat /root/note.txt I love Linux ​为 note.txt 在 / 下创建软链接 note.lnk[rootchcsa-study ~]# ln -s /root/note.txt /note.lnk [rootchcsa-study ~]# ls -l /note.lnk lrwxrwxrwx. 1 root root 14 4月 7日 09:50 /note.lnk - /root/note.txt ​为 note.txt 在 /tmp 下创建硬链接 note.bak[rootchcsa-study ~]# ln /root/note.txt /tmp/note.bak [rootchcsa-study ~]# ls -l /tmp/note.bak -rw-r--r--. 2 root root 13 4月 7日 09:43 /tmp/note.bak ​查看三个文件的 inode 号说明软硬链接区别[rootchcsa-study ~]# ls -i /root/note.txt /note.lnk /tmp/note.bak 751689 /note.lnk 751093 /root/note.txt 751093 /tmp/note.bak ​ 软链接 概念 window的快捷方式 作用在默认路径可以快速操作其他路径下的文件便捷管理 特点删除快捷方式源文件没影响删除源文件快捷方式失效 ​ 硬链接 概念多个文件名指向同一个inode节点号 作用文件名进行备份数据区并有备份防止误删除 特点多个文件共享一个inode节点区通过硬链接次数查看文件是否有备份 注意不能对目录文件进行创建不能跨分区操作四、文本查看与 Vim 操作查看 /etc/passwd 的前 8 行、后 5 行[rootchcsa-study ~]# head -n 8 /etc/passwd [rootchcsa-study ~]# tail -n 5 /etc/passwd用 cat 显示 /etc/passwd 并带行号[rootchcsa-study ~]# cat -n /etc/passwd ​用 Vim 打开 /root/note.txt完成[rootchcsa-study ~]# vim /root/note.txt ​复制全文到末尾gg 1G G P给所有行加 # 注释:%/^/#/删除所有空行:g/^$/d保存退出:wq五、重定向、管道与文本处理把 ls / 的结果输出到 /root/list.txt[rootchcsa-study ~]# ls / /root/list.txt把 echo RHCSA 2026 追加到 /root/list.txt[rootchcsa-study ~]# echo RHCSA 2026 /root/list.txt统计 /etc/passwd 一共有多少行即多少用户[rootchcsa-study ~]# wc -l /etc/passwd 39 /etc/passwd截取 /etc/passwd 中 第一个字段用户名 并输出[rootchcsa-study ~]# cut -d: -f1 /etc/passwd过滤出 /etc/passwd 中包含 root 的所有行[rootchcsa-study ~]# grep root /etc/passwd六、查找、压缩与用户及别名查找系统中所有 .log 结尾且小于 100k 的文件[rootchcsa-study ~]# find / -name *.log -size -100k把 /root/test 打包压缩为 linux_test.tar.gz[rootchcsa-study ~]# tar -czf linux_test.tar.gz /root/test创建组 it[rootchcsa-study ~]# groupadd it

更多文章