1.进入/tmp目录,创建mytest目录,在其下创建两个目录dirl,dir2;
2.把/etc/profile文件拷贝到/tmp/mytest目录中;
3.进入/tmp/mytest目录,重命名profile文件为profile_copy;
4.把profile_copy移动到dir1中,再把dir1移动到dir2中;
5.查看/tmp/mytest下各级目录数据。
< >
< >
Linux基本命令动手实践2-1
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
关注让【道友老李】来帮你解答,本回答参考通义千问qwen-plus编写,并整理提供,如果还有疑问可以点击头像关注,评论或留言
### 问题解答1. 进入
/tmp目录,创建mytest目录,在其下创建两个目录dirl和dir2cd /tmp mkdir -p mytest/dirl mytest/dir22. 把
/etc/profile文件拷贝到/tmp/mytest目录中cp /etc/profile /tmp/mytest/3. 进入
/tmp/mytest目录,重命名profile文件为profile_copycd /tmp/mytest mv profile profile_copy4. 把
profile_copy移动到dirl中,再把dirl移动到dir2中mv profile_copy dirl/ mv dirl dir2/5. 查看
/tmp/mytest下各级目录数据tree /tmp/mytest案例
假设我们按照上述步骤操作,以下是可能的输出结果:
$ cd /tmp $ mkdir -p mytest/dirl mytest/dir2 $ cp /etc/profile /tmp/mytest/ $ cd /tmp/mytest $ mv profile profile_copy $ mv profile_copy dirl/ $ mv dirl dir2/ $ tree /tmp/mytest /tmp/mytest └── dir2 └── dirl └── profile_copy 2 directories, 1 file代码示例
如果你希望将这些命令封装在一个脚本中,可以使用以下 Bash 脚本:
#!/bin/bash # 进入 /tmp 目录 cd /tmp # 创建 mytest 目录及其子目录 mkdir -p mytest/dirl mytest/dir2 # 拷贝 /etc/profile 到 /tmp/mytest cp /etc/profile /tmp/mytest/ # 进入 /tmp/mytest 目录 cd /tmp/mytest # 重命名 profile 文件为 profile_copy mv profile profile_copy # 移动 profile_copy 到 dirl 中 mv profile_copy dirl/ # 移动 dirl 到 dir2 中 mv dirl dir2/ # 查看 /tmp/mytest 下各级目录数据 tree /tmp/mytest运行脚本
- 将上述脚本保存为
setup.sh。 - 赋予脚本执行权限:
chmod +x setup.sh- 运行脚本:
./setup.sh这样,你就可以一次性完成所有操作,并查看最终的目录结构。
解决 无用评论 打赏 举报- 将上述脚本保存为