RHCA作业
-
基础文件和目录操作
(1). 在用户主目录下创建一个名为test_dir的目录,并在该目录中创建一个名为test_file.txt的空文本文件。
[root@localhost ~]# mkdir test_dir
[root@localhost ~]# cd /test_dir
[root@localhost test_dir]# touch test_file.txt
(2). 将test_file.txt文件复制到/tmp目录下,并将复制后的文件重命名为copy_of_test.txt。
[root@localhost test_dir]# cp test_file.txt /tmp/copy_of_test.txt
(3). 删除test_dir目录及其下的所有文件(包括test_file.txt),请使用一个命令完成此操作。
[root@localhost ~]# rm -rf test_dir [root@localhost ~]# ls 公共 图片 音乐 file.txt test.txt 模板 文档 桌面 mysql84-community-release-el9-1.noarch.rpm 视频 下载 anaconda-ks.cfg test
(4)在test_dir目录(如果已删除可重新创建)下创建一个test_file.txt文件,然后再创建该文件的软链接链接名为soft_link.txt,再创建一个硬链接,链接名为hard_link.txt。
[root@localhost test_dir]# ln -s test_file.txt soft_link.txt [root@localhost test_dir]# ln test_file.txt hard_link.txt
(3). 删除test_file.txt文件,查看软链接和硬链接文件是否还能访问,分别说明原因。
rm:是否删除普通空文件 'test_file.txt'?y [root@localhost test_dir]# cat soft_link.txt cat: soft_link.txt: 没有那个文件或目录 [root@localhost test_dir]# cat hard_link.txt
硬链接可任意,防止误删除文件,对文件名进行备份
软连接不可以,相当于windows下的快捷方式
-
文件内容查看与编辑
(1). 使用合适的命令查看/etc/passwd文件的前 10 行内容。
硬链接:防止误删除文件,对文件名进行备份
(2). 向copy_of_test.txt文件中追加一行内容 “这是追加的测试内容”,并使用命令查看文件内容确认追加成功。
[root@localhost ~]# echo 这是追加的测试内容 >> copy_of_test.txt [root@localhost ~]# vim copy_of_test.txt
(3). 使用文本编辑器(如vim)打开copy_of_test.txt文件,将 “测试” 替换为 “练习”,保存并退出编辑器。
[root@localhost ~]# vim copy_of_test.txt
i
这是追加的练习内容
esc
:wq
-
综合操作
(1).在/home目录下创建一个名为backup的目录,将/etc目录下所有以.conf结尾的文件复制到backup目录中。
[root@localhost ~]# find /etc/ -type f -name "*.conf" -exec cp {} backup/ \;
(2). 统计backup目录中文件的数量,并输出结果。
[root@localhost backup]# ls | wc -l 261
(3).将backup目录打包成一个名为etc_backup.tar.gz的压缩包,并删除原始的backup目录
[root@localhost ~]# tar -czf etc_backup.tar.gz backup [root@localhost ~]# ll 总用量 240 -rw-r--r--. 1 root root 200023 10月 16 21:19 etc_backup.tar.gz [root@localhost ~]# rm -f backup
4. 文件权限管理
(1).将copy_of_test.txt文件的所有者修改为当前系统中的普通用户user1(假设user1存在),文件所属组修改为group1(假设group1存在)。
[root@localhost ~]# useradd user1 [root@localhost ~]# groupadd group1 [root@localhost ~]# chown user1:group1 copy_of_test.txt
(2).为copy_of_test.txt文件设置权限,使得所有者有读写执行权限,所属组有读和执行权限,其他用户只有读权限,写出具体命令。
[root@localhost ~]# chmod 752 copy_of_test.txt
(3).查看copy_of_test.txt文件的详细权限信息。
[root@localhost ~]# ls -l copy_of_test.txt -rwxr-x-w-. 1 user1 group1 28 10月 16 20:40 copy_of_test.txt
-
用户和用户组基础操作
(1).创建一个名为newuser1的普通用户,并指定其默认登录 Shell 为/bin/bash。
[root@localhost ~]# useradd -s /bin/bash newuser1
(2).创建一个名为newgroup1的用户组,然后将newuser1添加到该用户组中。
[root@localhost ~]# groupadd newgroup1
[root@localhost ~]# usermod -a -G newgroup1 newuser1
(3).删除用户newuser1,要求保留其家目录。
[root@localhost ~]# userdel newuser1
6. 文件和目录权限设置与修改
(1).在用户主目录下创建一个名为perm_test_dir的目录和perm_test_file.txt的文件,分别为该目录和文件设置权限:目录的所有者有读写执行权限,所属组有读和执行权限,其他用户无任何权限;文件的所有者有读写权限,所属组和其他用户只有读权限。
[root@localhost ~]# mkdir perm_test_dir
[root@localhost ~]# touch perm_test_file.txt
[root@localhost ~]# chmod 750 perm_test_dir
[root@localhost ~]# chmod 644 perm_test_file.txt
(2).将perm_test_dir目录及其下所有文件的所属组修改为newgroup1。
[root@localhost ~]# chgrp -R newgroup1 perm_test_dir
(3).递归地将perm_test_dir目录的权限修改为:所有者和所属组有读写执行权限,其他用户只有读权限。
[root@localhost ~]# chmod -R 774 perm_test_dir
7.写出通过dnf安装cockpit的详细过程。
[root@localhost ~]# dnf -y install cockpit
[root@localhost ~]# systemctl start cocoipt
[root@localhost ~]# system stop firewalld
[root@localhost ~]# systemctl restart cocoipt