1. 基础文件和目录操作
(1). 在用户主目录下创建一个名为test_dir的目录,并在该目录中创建一个名为test_file.txt的空文本文件。
[root@localhost ~]# mkdir /test_dir
[root@localhost ~]# ls #查看是否创建成功
anaconda-ks.cfg QQ_3.2.19_250904_aarch64_01.rpm test_dir
[root@localhost ~]# cd /test_dir
[root@localhost test_dir]# touch test_file.txt
[root@localhost test_dir]# ls #查看是否创建成功
test_file.txt
(2). 将test_file.txt文件复制到/tmp目录下,并将复制后的文件重命名为copy_of_test.txt。
[root@localhost /]# cp /test_dir/test_file.txt /tmp/copy_of_test.txt
[root@localhost /]# ls /tmp
copy_of_test.txt
(3). 删除test_dir目录及其下的所有文件(包括test_file.txt),请使用一个命令完成此操作。
[root@localhost /]# rm -rf ~/test_dir
[root@localhost /]# ls ~
anaconda-ks.cfg QQ_3.2.19_250904_aarch64_01.rpm
(4)在test_dir目录(如果已删除可重新创建)下创建一个test_file.txt文件,然后再创建该文件的软链接链接名为soft_link.txt,再创建一个硬链接,链接名为hard_link.txt。
软链接:
[root@localhost /]# ln -s /test_dir/test_file.txt /test_dir/soft_link.txt
[root@localhost /]# ls /test_dir
soft_link.txt test_file.txt
硬链接:
[root@localhost /]# ln /test_dir/test_file.txt /test_dir/hard_link.txt
[root@localhost /]# ls /test_dir
hard_link.txt soft_link.txt test_file.txt
(3). 删除test_file.txt文件,查看软链接和硬链接文件是否还能访问,分别说明原因。
[root@localhost /]# rm -rf /test_dir/test_file.txt
[root@localhost /]# ls /test_dir
hard_link.txt soft_link.txt #soft_link.txt 变红
| 链接类型 | 删除原文件后是否可访问 | 原因 |
|---|---|---|
| 软链接 | 不可访问 | 软链接仅指向原文件路径,路径失效后链接失效。 |
| 硬链接 | 可访问 | 硬链接与原文件共享 inode,删除原文件不影响硬链接。 |
2. 文件内容查看与编辑
(1). 使用合适的命令查看/etc/passwd文件的前 10 行内容。
[root@localhost /]# head /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
head默认前十行,可直接使用head /etc/passwd查询
也可通过head -n 10 /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文件,将 “测试” 替换为 “练习”,保存并退出编辑器。
vim copy_of_test.txt
:%s /测试/练习/g
:wq
3. 综合操作
(1).在/home目录下创建一个名为backup的目录,将/etc目录下所有以.conf结尾的文件复制到backup目录中。
[root@localhost ~]# cd /home
[root@localhost home]# mkdir backup
[root@localhost home]# ls
backup newuser1 root123
[root@localhost home]# cp /etc/*.conf /home/backup
[root@localhost home]# ls /backup
appstream.conf dracut.conf krb5.conf logrotate.conf pnm2ppa.conf sudo.conf vconsole.conf
asound.conf fprintd.conf ld.so.conf man_db.conf resolv.conf sudo-ldap.conf xattr.conf
brltty.conf fuse.conf libaudit.conf mke2fs.conf rsyncd.conf sysctl.conf yum.conf
chrony.conf host.conf libuser.conf nsswitch.conf rsyslog.conf updatedb.conf
dnsmasq.conf kdump.conf locale.conf pbm2ppa.conf sestatus.conf usb_modeswitch.conf
(2). 统计backup目录中文件的数量,并输出结果。
[root@localhost home]# ls /backup | wc -l
33
(3).将backup目录打包成一个名为etc_backup.tar.gz的压缩包,并删除原始的backup目录。
[root@localhost home]# tar -zcvf etc_backup.tar.gz /home/backup
[root@localhost home]# rm -rf /home/backup
[root@localhost home]# ls /home
etc_backup.tar.gz newuser1 root123
4. 文件权限管理
(1).将copy_of_test.txt文件的所有者修改为当前系统中的普通用户user1(假设user1存在),文件所属组修改为group1(假设group1存在)。
chown user1:group1 /tmp/copy_of_test.txt
(2).为copy_of_test.txt文件设置权限,使得所有者有读写执行权限,所属组有读和执行权限,其他用户只有读权限,写出具体命令。
[root@localhost home]# chmod 754 /tmp/copy_of_test.txt
[root@localhost home]# ls -l /tmp/copy_of_test.txt
-rwxr-xr--. 1 root root 0 10月 16 19:49 /tmp/copy_of_test.txt
这里可用多种方法如:
1、[root@localhost home]# chmod 754 /tmp/copy_of_test.txt
2、[root@localhost home]#chmod u=rwx,g=rx,o=r /tmp/copy_of_test.txt
(3).查看copy_of_test.txt文件的详细权限信息。
[root@localhost home]# ls -l /tmp/copy_of_test.txt
-rwxr-xr--. 1 root root 0 10月 16 19:49 /tmp/copy_of_test.txt
5. 用户和用户组基础操作
(1).创建一个名为newuser1的普通用户,并指定其默认登录 Shell 为/bin/bash。
[root@localhost ~]# useradd -s /bin/bash newuser1
创建后默认登录 Shell 为/bin/bash/bin/bash 可直接useradd 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 ~]# ls
anaconda-ks.cfg copy_of_test.txt perm_test_dir perm_test_file.txt QQ_3.2.19_250904_aarch64_01.rpm
[root@localhost ~]# chmod 750 ~/perm_test_dir
[root@localhost ~]# chmod 644 ~/perm_test_file.txt
[root@localhost ~]# ls -ld perm_test_dir
drwxr-x---. 2 root root 6 10月 16 20:41 perm_test_dir
[root@localhost ~]# ls -l ~/perm_test_file.txt
-rw-r--r--. 1 root root 0 10月 16 20:41 /root/perm_test_file.txt
(2).将perm_test_dir目录及其下所有文件的所属组修改为newgroup1。
[root@localhost ~]# chgrp -R newgroup1 ~/perm_test_dir
[root@localhost ~]# ls -ld perm_test_dir
drwxr-x---. 2 root newgroup1 6 10月 16 20:41 perm_test_dir
(3).递归地将perm_test_dir目录的权限修改为:所有者和所属组有读写执行权限,其他用户只有读权限。
[root@localhost ~]# chmod -R 774 ~/perm_test_dir
7.写出通过dnf安装cockpit的详细过程。
首先挂载:
[root@localhost ~]# mount /dev/sr0/mnt
然后配置本地YUM仓库,用于从挂载的ISO镜像安装软件
[root@localhost ~]#vim /etc/yum.repos.d/base.repo
[BaseOS]
#组名
name=BaseOS
#描述名称
baseurl=file:///mnt/BaseOS
#资源路径
gpgcheck=0
[AppStream]
name=App
baseurl=file:///mnt/AppStream
gpgcheck=0
:wq #保存退出
最后安装并启动cockpit Web管理工具并关闭防火墙
[root@localhost ~]#dnf install cockpit -y
[root@localhost ~]#systemctl restart cockpit
[root@localhost ~]#systemctl stop firewalld
windows浏览器访问网址 虚拟机的ip:9090
1272

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



