Skip to content

Lab1

网络攻防实战

241840273 杨良灼

(1)

mkdir tmp
cd tmp
mkdir test

1-1

(2)

man touch

1-2

(3)

cd test
touch test

1-3

(4)

echo -e '#!/bin/sh\n' > test
echo 'curl --head --silent https://www.nju.edu.cn' >> test

1-4

(5)

./test

1-5

(6)

chmod u+rwx test

1-6

(7)

shebang: sharp(#) + bang(!) or hash(#) + bang(!)

以指令 #!/bin/sh 开头的文件执行时会实际调用 /bin/sh ,也就是使用了 sh 来解析.

所以执行 (4) 中编写的文件实际上就是调用 /bin/sh 执行 curl 命令

使用 man curl 查询得到:

--head
    (HTTP FTP FILE) Fetch the headers only. HTTP-servers feature the command HEAD which this uses to  get  nothing but the header of a document. When used on an FTP or FILE URL, curl displays the file size and last modification time only.
    Providing --head multiple times has no extra effect. Disable it again with --no-head.

--silent
    Silent or quiet mode. Do not show progress meter or error messages. Makes curl mute. It still outputs the data you ask for, potentially even to the terminal/stdout unless you redirect it.
    Use -S, --show-error in addition to this option to disable progress meter but still show error messages.
    Providing --silent multiple times has no extra effect. Disable it again with --no-silent.

(8)

./test | tail -n 5 > last-5-lines.txt
nl last-5-lines.txt

1-7

这里 ./test 返回结果最后一行仅含一个回车,所以这里看起来只有四行,但实际上有五行.