1.基础文件和目录操作
(1). 在用户主目录下创建一个名为test_dir的目录,并在该目录中创建一个名为test_file.txt的空文本文件。
[root@localhost ~]# mkdir ~/test_dir
[root@localhost ~]# touch ~/test_dir/test_file.txt
(2). 将test_file.txt文件复制到/tmp目录下,并将复制后的文件重命名为copy_of_test.txt。
[root@localhost ~]# cp test_file.txt /tmp/copy_of_test.txt
(3). 删除test_dir目录及其下的所有文件(包括test_file.txt),请使用一个命令完成此操作。
[root@localhost ~]# rm -rf test_dir
(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文件,查看软链接和硬链接文件是否还能访问,分别说明原因。
软链接不能访问,软链接相当于是一个快捷方式
硬链接能继续访问,硬链接的作用是防止误删除文件,进行备份
2.文件内容查看与编辑
(1). 使用合适的命令查看/etc/passwd文件的前 10 行内容。
[root@localhost test_dir]# head /etc/passwd
(2). 向copy_of_test.txt文件中追加一行内容 “这是追加的测试内容”,并使用命令查看文件内容确认追加成功。
[root@localhost ~]# echo "这是追加的测试内容" >> copy_of_test.txt
[root@localhost ~]# cat copy_of_test.txt
(3). 使用文本编辑器(如vim)打开copy_of_test.txt文件,将 “测试” 替换为 “练习”,保存并退出编辑器。
[root@localhost ~]# vim copy_of_test.txt
[root@localhost ~]# cat copy_of_test.txt
3.综合操作
(1).在/home目录下创建一个名为backup的目录,将/etc目录下所有以.conf结尾的文件复制到backup目录中。
[root@localhost etc]# cp /etc/*.conf /home/backup
(2). 统计backup目录中文件的数量,并输出结果。
[root@localhost home]# ls -l backup
total 200
(3).将backup目录打包成一个名为etc_backup.tar.gz的压缩包,并删除原始的backup目录。
[root@localhost home]# tar -czf etc_backup.tar.gz backup
[root@localhost home]# ls
backup etc_backup.tar.gz rhelHeat z
[root@localhost home]# rm -rf backup
4. 文件权限管理
(1).将copy_of_test.txt文件的所有者修改为当前系统中的普通用户user1(假设user1存在),文件所属组修改为group1(假设group1存在)。
[root@localhost home]# chown user1:group1 copy_of_test.txt
(2).为copy_of_test.txt文件设置权限,使得所有者有读写执行权限,所属组有读和执行权限,其他用户只有读权限,写出具体命令。
[root@localhost ~]# chmod 754 copy_of_test.txt
(3).查看copy_of_test.txt文件的详细权限信息。
[root@localhost ~]# ls -l copy_of_test.txt
-rwxr-xr--. 1 root root 28 Oct 16 08:02 copy_of_test.txt
5.用户和用户组基础操作
(1).创建一个名为newuser1的普通用户,并指定其默认登录 Shell 为/bin/bash。
[root@localhost ~]# useradd newuser1 -s /bin/bash
[root@localhost ~]# id newuser1
uid=1001(newuser1) gid=1001(newuser1) groups=1001(newuser1)
(2).创建一个名为newgroup1的用户组,然后将newuser1添加到该用户组中。
[root@localhost ~]# gpasswd -a newuser1 newgroup1
Adding user newuser1 to group newgroup1
(3).删除用户newuser1,要求保留其家目录。
[root@localhost ~]# userdel -r newuser1
6. 文件和目录权限设置与修改
(1).在用户主目录下创建一个名为perm_test_dir的目录和perm_test_file.txt的文件,分别为该目录和文件设置权限:目录的所有者有读写执行权限,所属组有读和执行权限,其他用户无任何权限;文件的所有者有读写权限,所属组和其他用户只有读权限。
[root@localhost ~]# chmod 750 perm_test_dir
[root@localhost ~]# chmod 744 perm_test_file.txt
(2).将perm_test_dir目录及其下所有文件的所属组修改为newgroup1。
[root@localhost ~]# chown :newgroup1 perm_test_dir
(3).递归地将perm_test_dir目录的权限修改为:所有者和所属组有读写执行权限,其他用户只有读权限。
[root@localhost ~]# chmod 774 perm_test_dir
7.写出通过dnf安装cockpit的详细过程。
(1)
#mount /dev/sr0 /mnt
(2)
[root@localhost ~]#vim /etc/yum.repos.d/base.repo [BaseOS] name=BaseOS baseurl=file:///mnt/BaseOS gpgcheck=0 [AppStream] name=AppStream baseurl=file:///mnt/AppStream gpgcheck=0
(3)
dnf install cockpit -y
(4)
systemctl stop firewalld

792

被折叠的 条评论
为什么被折叠?



