missing semester - 作业1

文章展示了在Linux环境中使用Shell进行目录操作、创建文件、设置权限以及执行脚本的过程。用户尝试通过bash编写一个获取远程HTTP头信息的脚本,遇到权限问题和curl命令缺失的问题,最终通过修改权限和安装curl解决了问题。
摘要由CSDN通过智能技术生成

1.

vm@vm-virtual-machine:~/Desktop$ echo $SHELL
/bin/bash

 2.

vm@vm-virtual-machine:/home$ cd ..
vm@vm-virtual-machine:/$ pwd
/
vm@vm-virtual-machine:/$ ls
bin    dev   lib    libx32      mnt   root  snap      sys  var
boot   etc   lib32  lost+found  opt   run   srv       tmp
cdrom  home  lib64  media       proc  sbin  swapfile  usr
vm@vm-virtual-machine:/$ mkdir /tmp/missing
vm@vm-virtual-machine:/$ pwd
/
vm@vm-virtual-machine:/$ cd /tmp
vm@vm-virtual-machine:/tmp$ ls
missing
snap-private-tmp
snap.snapd-desktop-integration
systemd-private-26f510d262a34be8bf25f04c1bf7676f-bluetooth.service-CMy6I7
systemd-private-26f510d262a34be8bf25f04c1bf7676f-colord.service-Tx7U4V
systemd-private-26f510d262a34be8bf25f04c1bf7676f-ModemManager.service-Z519d9
systemd-private-26f510d262a34be8bf25f04c1bf7676f-power-profiles-daemon.service-1KnaCk
systemd-private-26f510d262a34be8bf25f04c1bf7676f-switcheroo-control.service-pPtgRh
systemd-private-26f510d262a34be8bf25f04c1bf7676f-systemd-logind.service-4fvAXy
systemd-private-26f510d262a34be8bf25f04c1bf7676f-systemd-oomd.service-qsT3bv
systemd-private-26f510d262a34be8bf25f04c1bf7676f-systemd-resolved.service-wRsCSw
systemd-private-26f510d262a34be8bf25f04c1bf7676f-systemd-timesyncd.service-cwQDPB
systemd-private-26f510d262a34be8bf25f04c1bf7676f-upower.service-sdB8CO
tracker-extract-3-files.1000
tracker-extract-3-files.127
VMwareDnD
vmware-root_579-3979708611

3.

vm@vm-virtual-machine:/$ man touch

4.

vm@vm-virtual-machine:/$ pwd
/
vm@vm-virtual-machine:/$ cd missing
bash: cd: missing: No such file or directory
vm@vm-virtual-machine:/$ pwd
/
vm@vm-virtual-machine:/$ cd tmp/missing/
vm@vm-virtual-machine:/tmp/missing$ ls
vm@vm-virtual-machine:/tmp/missing$ touch semester.txt
vm@vm-virtual-machine:/tmp/missing$ ls
semester.txt

5.

vm@vm-virtual-machine:/tmp/missing$ echo '#!/bin/sh' > semester.txt
vm@vm-virtual-machine:/tmp/missing$ echo curl --head --silent https://missing.csail.mit.edu >> semester.txt
vm@vm-virtual-machine:/tmp/missing$ cat -n semester.txt
     1	#!/bin/sh
     2	curl --head --silent https://missing.csail.mit.edu

也可以用vim写入

6.

vm@vm-virtual-machine:/tmp/missing$ ./semester.txt
bash: ./semester.txt: Permission denied
vm@vm-virtual-machine:/tmp/missing$ ls -l
total 4
-rw-rw-r-- 1 vm vm 61  3月 21 14:40 semester.txt

无法执行,原因是文件所有者无执行权限(权限为rw-,只可读写)

7.

vm@vm-virtual-machine:/$ man chmod

8.

vm@vm-virtual-machine:/tmp/missing$ sh semester
semester: 2: curl: not found

因为没装Curl,用以下命令安装:

sudo apt-get update
sudo apt-get install curl

 于是有:

vm@vm-virtual-machine:/tmp/missing$ sh semester
HTTP/2 200 
server: GitHub.com
content-type: text/html; charset=utf-8
x-origin-cache: HIT
last-modified: Mon, 20 Mar 2023 11:05:13 GMT
access-control-allow-origin: *
etag: "64183de9-1f86"
expires: Mon, 20 Mar 2023 12:27:46 GMT
cache-control: max-age=600
x-proxy-cache: MISS
x-github-request-id: FBE4:3E92:9BE09:10268E:64184EEA
accept-ranges: bytes
date: Tue, 21 Mar 2023 07:24:51 GMT
via: 1.1 varnish
age: 0
x-served-by: cache-nrt-rjtf7700056-NRT
x-cache: HIT
x-cache-hits: 1
x-timer: S1679383492.688454,VS0,VE304
vary: Accept-Encoding
x-fastly-request-id: f046c5a8fa1c5479dd625f4092e371e1c94b8ddf
content-length: 8070

用./semester运行:

vm@vm-virtual-machine:/tmp/missing$ ./semester
HTTP/2 200 
server: GitHub.com
content-type: text/html; charset=utf-8
last-modified: Mon, 20 Mar 2023 11:05:13 GMT
access-control-allow-origin: *
etag: "64183de9-1f86"
expires: Tue, 21 Mar 2023 07:49:00 GMT
cache-control: max-age=600
x-proxy-cache: MISS
x-github-request-id: 3D6C:4D5F:241E92:26D5D3:64195F14
accept-ranges: bytes
date: Tue, 21 Mar 2023 07:39:00 GMT
via: 1.1 varnish
age: 0
x-served-by: cache-tyo11958-TYO
x-cache: MISS
x-cache-hits: 0
x-timer: S1679384341.627790,VS0,VE177
vary: Accept-Encoding
x-fastly-request-id: e406ae07c4099bb1e5d7b5d58427e0955c190c26
content-length: 8070

#!是一个特殊符号,/bin/sh是用来解释该脚本的的shell路径

注:最开始把 #!/bin/sh 误输入为 #!bin/sh/ 

9.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值