Post

BUAA-OS-lab0

BUAA-OS-lab0

lab0 实验报告

思考题

Thinking 0.1

执行 git status > Utracked.txt 后,观察文件内容不难发现,此时有两个文件 README.txt 和 Untracked.txt 是 Untracked 的,此时它们处于工作区,没有进入暂存区。

执行 git add .git status > Stage.txt 之后,观察 Stage.txt 的内容,可以发现先前的两个文件已经被全部加入暂存区,但没有被提交;而刚刚新建的 Stage.txt 没有进入暂存区,处于工作区。

执行 git commit -m "22371053" 后,观察终端中返回的内容,发现两个位于暂存区的文件已经被提交成功了,而提交的说明信息为 22371053.

README.txt 两次状态的不同在于,一次还位于工作区,没有进入到暂存区;第二次已经处于暂存区内,没有被提交。

修改 README.txt 文件,再执行命令 git status > Modified.txt,这时与第一次的 status 不同。因为此时的 README.txt 状态是被修改,而不是第一次的新建添加。

Thinking 0.2

add the file 对应 git init

stage the file 对应 git add

commit 对应 git commit

Thinking 0.3

git checkout -- print.c

git reset HEAD --print.c
git checkout --print.c

git reset HEAD hello.txt

Thinking 0.4

完成三次提交后,执行 git log 命令,获取了三次提交的哈希值分别为 4586f0436ab657de6491ab4d8811b0a90957cab7, 142beda4696509e117456919df8e5f5e550cc8b5, 48499f657051e1dd78898739a411f2411d865662

执行 git reset --hard HEAD^ 进行版本回退后,查看当前 log,发现版本已经成功回退到第二次提交时的版本。

使用版本 1 的哈希值回退后,HEAD 现在位于 4586f04 1

使用版本 3 的哈希值回到新版本后,当前的版本已经成功回到第三次提交时的版本。

Thinking 0.5

执行 echo first 命令行输出 first

执行 echo second > output.txt 后命令行无输出,output.txt内容为 second

执行 echo third > output.txt 后命令行无输出,output.txt 被覆盖写入内容 third

执行 echo forth >> output.txt 后命令行无输出,output.txt 被追加写入内容 forth,当前内容为 thirdforth

Thinking 0.6

echo 'Shell Start... ' > testecho 
echo 'set a = 1 ' >> testecho 
echo 'a=1 ' >> testecho 
echo 'echo set b = 2 ' >> testecho 
echo 'b=2 ' >> testecho 
echo 'echo set c = a+b ' >> testecho 
echo 'c=$ [$a+$b] ' >> testecho 
echo 'echo c = $c ' >> testecho 
echo 'echo save c to ./file1 ' >> testecho 
echo 'echo $c>file1 ' >> testecho 
echo 'echo save b to ./file2 ' >> testecho 
echo 'echo $b>file2 ' >> testecho 
echo 'echo save a to ./file3 ' >> testecho 
echo 'echo $a>file3' >> testecho 
echo 'echo save file1 file2 file3 to file4 ' >> testecho 
echo 'cat file1>file4 ' >> testecho 
echo 'cat file2>>file4 ' >> testecho 
echo 'cat file3>>file4 ' >> testecho 
echo 'echo save file4 to ./result ' >> testecho 
echo 'cat file4>>result' >> testecho 
chmod +x test
./test 
cat result

执行后,分别创建了file1, file2, file3,写入了 a, b, c 的值,即 3, 2, 1。

把 file1 的内容写入到 file4;file2 和 file3 的内容追加在 file4 后;然后再把 file4 的内容追加在 result 文件里。最后 result 文件的内容为:

321

“echo Shell Start” 与 “echo echo Shell Start” 是有区别的。前者会直接打印 “echo Shell Start”,而后者会执行命令 “echo Shell Start”,然后将其输出作为文本传递给外部的 echo 命令,效果是相当于执行了两次 echo 命令。

“echo echo $c>file1” 与 “echo echo $c>file1” 也是有区别的。第一个命令会将字符串 “echo $c” 写入到 file1 文件中,而第二个命令会首先执行命令 “echo $c”,然后将其结果输出。

实验难点分析

在本周的上机实验中,主要考查了 shell 脚本的编写和 Linux 基本命令的使用。

主要的困难出现在对于脚本中 for, while 循环语句的使用不够熟练,以及 sed, awk 等命令掌握的不够熟练,在上机过程中需要经常查看 help 或 man。

实验体会

在 lab0 的课上和课下实验中,我对 git 的认知更加深刻,并且有了使用 git 的实际应用场景,在实际需求下应用 git 可以让我更深刻的掌握好 git 的基本使用方法。例如在完成课下实验时,曾错误的修改了一个文件,这时就使用了 git 的版本回滚功能,否则要找回原来的文件内容会比较麻烦。

在课上实验时,由于对很多指令掌握不够熟练,需要多次查阅指导书,或是通过 --help 来在终端查看帮助。查阅已有资料也是一个很重要的能力,这让我能够快速上手一个新指令的使用方法。

This post is licensed under CC BY 4.0 by the author.