练习背景: 您的主目录中累积了几个文件,您决定对其进行整理。您计划创建多个新子目录,并来回复制和移动您的文件以适合您的新架构。此外,您必须删除完全不需要的多个文件。
练习目标: 通过将文件放置于相应的子目录中,主目录更加整齐有序。
练习说明:
1. 使用密码 student 以用户 student 身份登录。如果您正在使用图形环境,请通过依次单击应用程序->附件->终端启动终端。
2. 登录系统后,您应立即位于主目录中。使用“打印工作目录”命令验证这一点。[student@stationX ~]$ pwd
/home/student
3. 使用以下命令之一查看您的主目录中是否包含任何文件:
ls
ls -a
ls -al
为什么第一条和第二条命令返回的文件数量不同?
根据第三条命令的报告,当前您主目录中最大文件的大小是多少?
4. 现在您将使用 touch 创建此序列所需的文件。后续单元将介绍扩展如何在以下命令中使用的详细信息。现在,只需如您看到的那样准确键入以下行(使用大括号 {},并在前两组集合之间插入下划线):
[student@stationX ~]$ touch {report,graph}_{jan,feb,mar}
5. 使用 ls 命令可查看之前命令的结果。您应该会发现,您的主目录中已创建以下六个新的空文件。
[student@stationX ~]$ ls
graph_feb graph_jan graph_mar report_feb report_jan report_mar
这些文件表示您将在余下的序列中使用的数据文件。如果由于某种原因您未看到这些文件,请向讲师寻求帮助;如果缺少这些文件,此实验的其余部分将无法正常工作。
6. 为了整理您的文件,您必须先创建一些新目录。使用 mkdir 创建几个目录。因为您更改了目录(如下所示),务必查看您的工作目录符合预期。
[student@stationX ~]$ mkdir Projects
[student@stationX ~]$ mkdir Projects/graphs
[student@stationX ~]$ cd Projects
[student@stationX Projects]$ mkdir reports
[student@stationX Projects]$ cd reports
[student@stationX reports]$ mkdir ../Backups
使用 ls 查看您的工作:
[student@stationX reports]$ cd
[student@stationX ~]$ ls -l
total 4
drwxr-xr-x 1 student student 0 Sep 30 21:07 Desktop
-rw-rw-r-- 1 student student 0 Sep 30 21:08 graph_feb
-rw-rw-r-- 1 student student 0 Sep 30 21:08 graph_jan
-rw-rw-r-- 1 student student 0 Sep 30 21:08 graph_mar
drwxrwxr-x 5 student student 4096 Sep 30 21:09 Projects
-rw-rw-r-- 1 student student 0 Sep 30 21:08 report_feb
-rw-rw-r-- 1 student student 0 Sep 30 21:08 report_jan
-rw-rw-r-- 1 student student 0 Sep 30 21:08 report_mar
[student@stationX ~]$ ls Projects
Backups graphs reports
7. 先将所有图形文件移动到项目目录的图形子目录。这一操作分为以下两个步骤:第一步是移动一个文件;第二步是移动两个文件:
[student@stationX ~]$ mv graph_jan Projects/graphs
[student@stationX ~]$ mv graph_feb graph_mar Projects/graphs
[student@stationX ~]$ ls -l Projects/graphs/
total 3
8. 接下来,将两个“报告”文件移动到项目目录的报告子目录中。使用一个命令移动这些文件:
[student@stationX ~]$ mv report_jan report_feb Projects/reports
[student@stationX ~]$ ls -l Projects/reports
total 2
9. 删除其余的报告文件:
[student@stationX ~]$ rm report_mar
Desktop
Projects
10. 更改为 Backups 目录并将一月的文件复制到此目录。使用绝对路径名称复制一个,使用相对路径名称复制另一个:
[student@stationX ~]$ cd Projects/Backups
[student@stationX Backups]$ pwd
/home/student/Projects/Backups
[student@stationX Backups]$ cp ../reports/report_jan .
[student@stationX Backups]$ cp
/home/student/Projects/graphs/graph_jan .
[student@stationX Backups]$ ls -l
-rw-rw-r-- 1 student student 0 Sep 30 21:20 graph_jan
-rw-rw-r-- 1 student student 0 Sep 30 21:20 report_jan
尾部点是目标:当前的工作目录。
11. 通过运行 exit 命令可注销或关闭您的图形终端。
http://www.51rhca.com/archives/137