Linux中怎么进student家目录,Linux 练习:目录和文件结构

练习背景: 您的主目录中累积了几个文件,您决定对其进行整理。您计划创建多个新子目录,并来回复制和移动您的文件以适合您的新架构。此外,您必须删除完全不需要的多个文件。

练习目标: 通过将文件放置于相应的子目录中,主目录更加整齐有序。

练习说明:

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

-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

8. 接下来,将两个“报告”文件移动到项目目录的报告子目录中。使用一个命令移动这些文件:

[student@stationX ~]$ mv report_jan report_feb Projects/reports

[student@stationX ~]$ ls -l Projects/reports

total 2

-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

9. 删除其余的报告文件:

[student@stationX ~]$ rm report_mar

[student@stationX ~]$ ls

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

total 2

-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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你想要在 Linux C 保存结构化数据,可以考虑将数据存储在一个二文件。为了方便操作,你可以按照固定大小的块来存储数据,每个块存储一个结构体。为了在文件保存固定数量的结构体数据,你需要知道每个结构体的大小和数据的总量。 以下是一个简单的实现,可以按照固定大小的块来存储结构体: ```c #include <stdio.h> #include <stdlib.h> typedef struct { int id; char name[20]; double score; } Student; #define BLOCK_SIZE 100 int main() { FILE *fp; char filename[100]; Student block[BLOCK_SIZE]; Student s; int num_blocks, num_students, i, j; printf("Enter filename: "); scanf("%s", filename); fp = fopen(filename, "wb"); if (fp == NULL) { printf("File cannot be opened.\n"); return 0; } printf("Enter number of students: "); scanf("%d", &num_students); num_blocks = num_students / BLOCK_SIZE; for (i = 0; i < num_blocks; i++) { for (j = 0; j < BLOCK_SIZE; j++) { s.id = i * BLOCK_SIZE + j + 1; sprintf(s.name, "Student%d", s.id); s.score = 100.0 - s.id * 0.5; block[j] = s; } fwrite(block, sizeof(Student), BLOCK_SIZE, fp); } int remaining = num_students % BLOCK_SIZE; if (remaining > 0) { for (j = 0; j < remaining; j++) { s.id = num_blocks * BLOCK_SIZE + j + 1; sprintf(s.name, "Student%d", s.id); s.score = 100.0 - s.id * 0.5; block[j] = s; } fwrite(block, sizeof(Student), remaining, fp); } fclose(fp); return 0; } ``` 这个程序会提示用户输入文件名和数据的总量,然后按照固定大小的块来存储数据。在这个例子,我们假设每个结构体的大小是固定的,并且按照顺序对每个结构行编号和命名。你可以根据实际情况来修改这个程序,并且根据需要添加读取数据的功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值