大一下作业2

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

分享文章

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

更多文章