作业1.1
1.基础文件和目录操作
(1)
mkdir ~/test_dir
Touch ~/test_dir/test_file.txt
(2)
cp ~/test_dir/test_file.txt /tmp/copy_of_test.txt
(3)
Rm -r ~/test_dir
(4)
bash
mkdir ~/test_dir
touch ~/test_dir/test_file.txt
ln -s ~/test_dir/test_file.txt ~/test_dir/soft_link.txt
ln ~/test_dir/test_file.txt ~/test_dir/hard_link.txt
软链接:软链接本质上是一个路径名的别名,指向原文件的路径。当原文件被删除后,软链接指向的路径不再存在,因而软链接变为“悬挂链接”(dangling link),访问时会报错。
硬链接:硬链接直接指向文件在磁盘上的 inode(数据块),与原文件等价。只要还有至少一个硬链接指向该 inode,文件的数据就会保留。删除原始文件仅是删除了其中一个目录项(链接),而硬链接仍然保持对同一 inode 的引用,所以文件仍然可用。
2.文件内容查看与编辑
(1)
bash
head -10 /etc/passwd
(2)
bash
echo "这是追加的测试内容" >> /tmp/copy_of_test.txt
cat /tmp/copy_of_test.txt
(3)
bash
vim /tmp/copy_of_test.txt
在 vim 中,输入 :%s/测试/练习/g (全局替换),然后按 Esc,输入 :wq 保存退出。
3. 综合操作
(1)
bash
mkdir /home/backup
cp /etc/*.conf /home/backup/
(2)
bash
ls /home/backup | wc -l
(3)
bash
tar -czvf etc_backup.tar.gz /home/backup
rm -rf /home/backup
4. 文件权限管理
(1)
bash
chown user1:group1 /tmp/copy_of_test.txt
(2)
bash
chmod u=rwx,g=rx,o=r /tmp/copy_of_test.txt
(3)
bash
ls -l /tmp/copy_of_test.txt
5. 用户和用户组基础操作
(1)
bash
useradd -s /bin/bash newuser1
(2)
bash
groupadd newgroup1
usermod -a -G newgroup1 newuser1
(3)
bash
userdel newuser1
6. 文件和目录权限设置与修改
(1)
bash
mkdir ~/perm_test_dir
touch ~/perm_test_dir/perm_test_file.txt
chmod 750 ~/perm_test_dir
chmod 644 ~/perm_test_dir/perm_test_file.txt
(2)
bash
chgrp -R newgroup1 ~/perm_test_dir
(3)
bash
chmod -R 774 ~/perm_test_dir
7. 通过 dnf 安装 cockpit 的详细过程
更新软件包列表:
bash
sudo dnf update
安装 cockpit 软件包:
bash
sudo dnf install cockpit
启动 cockpit 服务并设置开机自启:
bash
sudo systemctl start cockpit
sudo systemctl enable cockpit
确认 cockpit 服务状态:
bash
sudo systemctl status cockpit