- 基础文件和目录操作
(1). 在用户主目录下创建一个名为test_dir的目录,并在该目录中创建一个名为test_file.txt的空文本文件。
bash
[root@localhost ~]# mkdir ~/test_dir
root@localhost ~]# touch ~/test_dir/test_file.txt
(2). 将test_file.txt文件复制到/tmp目录下,并将复制后的文件重命名为copy_of_test.txt。
bash
[root@localhost ~]# cp ~/test_dir/test_file.txt /tmp/copy_of_test.txt
(3). 删除test_dir目录及其下的所有文件(包括test_file.txt),请使用一个命令完成此操作。
bash
[root@localhost ~]# rm -rf ~/test_dir
(4).在test_dir目录(如果已删除可重新创建)下创建一个test_file.txt文件,然后再创建该文件的软链接链接名为soft_link.txt,再创建一个硬链接,链接名为hard_link.txt。
bash
[root@localhost ~]# mkdir ~/test_dir
[root@localhost ~]# touch ~/test_dir/test_file.txt
[root@localhost ~]# ln -s ~/test_dir/test_file.txt soft_link.txt
[root@localhost ~]# ln ~/test_dir/test_file.txt hard_link.txt
(5). 删除test_file.txt文件,查看软链接和硬链接文件是否还能访问,分别说明原因。
bash
[root@localhost ~]# cat hard_link.txt
[root@localhost ~]# cat soft_link.txt
cat: soft_link.txt: 没有那个文件或目录
硬链接可以访问,软链接无法访问
硬链接是对原文件进行备份,与原文件共用一个数据区,所以可以访问。
软链接相当于Windows下的快捷方式,是快速匹配到原文件路径,原文件删除后没有路径就无法访问。
- 文件内容查看与编辑
(1). 使用合适的命令查看/etc/passwd文件的前 10 行内容。
bash
[root@localhost ~]# head -10 /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
(2). 向copy_of_test.txt文件中追加一行内容 "这是追加的测试内容",并使用命令查看文件内容确认追加成功。
bash
[root@localhost ~]# echo "这是追加的测试内容" >> /tmp/copy_of_test.txt
[root@localhost ~]# cat /tmp/copy_of_test.txt
这是追加的测试内容
(3). 使用文本编辑器(如vim)打开copy_of_test.txt文件,将 "测试" 替换为 "练习",保存并退出编辑器。
bash
[root@localhost ~]# vim /tmp/copy_of_test.txt
打开文本编辑器 按下i/a进入插入模式 光标移动到"测试"更改为"练习",按下esc进入命令模式,再按下:输入wq保存退出
- 综合操作
(1).在/home目录下创建一个名为backup的目录,将/etc目录下所有以.conf结尾的文件复制到backup目录中。
bash
[root@localhost ~]# mkdir /home/backup
[root@localhost ~]# cp /etc/*.conf /home/backup/
(2). 统计backup目录中文件的数量,并输出结果。
bash
[root@localhost ~]# ls /home/backup/ | wc -l
34
(3).将backup目录打包成一个名为etc_backup.tar.gz的压缩包,并删除原始的backup目录。
bash
[root@localhost ~]# tar -czvf etc_backup.tar.gz /home/backup
tar: 从成员名中删除开头的"/"
/home/backup/
/home/backup/appstream.conf
/home/backup/asound.conf
/home/backup/brltty.conf
/home/backup/chrony.conf
/home/backup/dnsmasq.conf
/home/backup/dracut.conf
/home/backup/fprintd.conf
/home/backup/fuse.conf
/home/backup/host.conf
/home/backup/kdump.conf
/home/backup/krb5.conf
/home/backup/ld.so.conf
/home/backup/libaudit.conf
/home/backup/libuser.conf
/home/backup/locale.conf
/home/backup/logrotate.conf
/home/backup/man_db.conf
/home/backup/mke2fs.conf
/home/backup/nsswitch.conf
/home/backup/pbm2ppa.conf
/home/backup/pnm2ppa.conf
/home/backup/request-key.conf
/home/backup/resolv.conf
/home/backup/rsyncd.conf
/home/backup/rsyslog.conf
/home/backup/sestatus.conf
/home/backup/sudo.conf
/home/backup/sudo-ldap.conf
/home/backup/sysctl.conf
/home/backup/updatedb.conf
/home/backup/usb_modeswitch.conf
/home/backup/vconsole.conf
/home/backup/xattr.conf
/home/backup/yum.conf
[root@localhost ~]# rm -rf /home/backup
(4).将当前主机/home/backup目录中的所有文件备份到另一台主机的/test目录。
bash
[root@localhost ~]# rsync -a /home/backup/ root@192.168.112.129:/test
- 文件权限管理
(1).将copy_of_test.txt文件的所有者修改为当前系统中的普通用户user1(假设user1存在),文件所属组修改为group1(假设group1存在)。
bash
[root@localhost ~]# chown user1:group1 /tmp/copy_of_test.txt
(2).为copy_of_test.txt文件设置权限,使得所有者有读写执行权限,所属组有读和执行权限,其他用户只有读权限,写出具体命令。
bash
[root@localhost ~]# chmod u=rwx,g=r-x,o=r-- /tmp/copy_of_test.txt
(3).查看copy_of_test.txt文件的详细权限信息。
bash
[root@localhost ~]# ll /tmp/copy_of_test.txt
-rwxr--r--. 1 root root 28 10月 19 19:20 /tmp/copy_of_test.txt
- 用户和用户组基础操作
(1).创建一个名为newuser1的普通用户,并指定其默认登录 Shell 为/bin/bash。
bash
[root@localhost ~]# useradd -s /bin/bash newuser1
(2).创建一个名为newgroup1的用户组,然后将newuser1添加到该用户组中。
bash
[root@localhost ~]# groupadd newgroup1
[root@localhost ~]# usermod -aG newgroup1 newuser1
(3).删除用户newuser1,要求保留其家目录。
bash
[root@localhost ~]# userdel newuser1
- 文件和目录权限设置与修改
(1).在用户主目录下创建一个名为perm_test_dir的目录和perm_test_file.txt的文件,分别为该目录和文件设置权限:目录的所有者有读写执行权限,所属组有读和执行权限,其他用户无任何权限;文件的所有者有读写权限,所属组和其他用户只有读权限。
bash
[root@localhost ~]# mkdir ~/perm_test_dir
[root@localhost ~]# touch ~/perm_test_dir/perm_test_file.txt
[root@localhost ~]# chmod u=rwx,g=r-x,o=--- ~/perm_test_dir
[root@localhost ~]# chmod u=rw-,g=r--,o=r-- ~/perm_test_dir/perm_test_file.txt
(2).将perm_test_dir目录及其下所有文件的所属组修改为newgroup1。
bash
[root@localhost ~]# chown -R :newgroup1 ~/perm_test_dir
(3).递归地将perm_test_dir目录的权限修改为:所有者和所属组有读写执行权限,其他用户只有读权限。
bash
[root@localhost ~]# chmod -R u=rwx,g=rwx,o=r-- ~/perm_test_dir
7.写出通过dnf以及本地源安装httpd的详细过程。
bash
rpm/dnf 本地源进行安装软件
1)光盘设备成功连接本地主机
2)将光盘设备手动挂在 /sr0
mount /dev/sr0 /sr0
echo 'mount /dev/sr0 /sr0'>> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
3)rpm 不能自动解决软件包之间的依赖关系
rpm -ivh
rpm -evh
-q 查询指定软件已经安装的包名
-qa 所有已安装的软件包
-ql 软件包释放的文件
-qf
4)yum/dnf/dnf-3 自动解锁依赖关系
编辑dnf软件仓库文件(yum配置文件)
[root@localhost ~]# vim /etc/yum.repos.d/base.repo
[BaseOS]
name=RHEL0.BaseOS
baseurl=file:///sr0/BaseOS/
gpgcheck=0
enabled=1
[AppStream]
name=App
baseurl=file:///sr0/AppStream/
gpgcheck=0
enabled=1
#dnf install httpd
卸载软件包:#dnf remove httpd
#systemctl start httpd
#echo welcome > var/www/html/index.html
#curl http://192.168.112.128