Shinkai005
2023/02/21阅读:13主题:极简黑
【格拉365天不摆烂行动】unix lab mac版本
【格拉365天不摆烂行动】unix lab mac版本.md
文件集合进行排序和处理。
在Moodle的Unix部分的Coursework文件夹中,你会发现一个名为un_sorted_files.zip的zip文件,其中包含许多不同类型的多个文件。
-
下载un_sorted_files.zip的zip文件, 复制在虚拟机主目录中
我还建议创建一个脚本目录,如 实验室第4部分
。
从这里开始,所有的任务(在任务1部分)必须只通过你的Linux脚本完成。
使用Unzip命令解压文件。你需要查找选项对于这个命令,你可以使用你在实验室学到的技术。
您的任务是编写一个名为process_files的脚本,它将从用户那里接受表示文件类型的3个字符串作为命令行参数。
然后必须创建4个目录—一个用于每种文件类型,另一个用于不匹配任何文件类型的文件—并将文件分离到这些新目录中,然后向用户返回关于这些文件的一些信息。
例如,如果用户输入process_files jpg gif docx (./process_files.sh jpg gif docx)
在处理它们之前,脚本将把jpg/jpeg、gif和doc/docx文件排序到相应的目录中,将其余文件排序到其他目录中。注意:所有的jpg/jpeg应该在同一个jpg目录下,所有的doc/docx应该在同一个docx目录下。
您的脚本需要输出5个不同的文件。在您创建的每个目录中,您 应该创建一个文件,其中包含该目录中按大小顺序排序的所有文件的列表。 此外,在主目录中,脚本应该输出一个包含每个标签的文件 目录和每个目录中的文件按反向字母顺序排序。这个文件应该 看起来像这样
这是一个很难构建的文件,因此在这一节中,复制该文件将获得满分格式。您可能需要创建几个临时文件来完成该任务。你仍然
通过创建某个描述的摘要文件,为本节获得一些标记。您的最后一个脚本任务是提供一个单独的清理脚本,它将删除文件和
从虚拟机创建的目录(请确保有备份副本在测试之前您的文件和脚本)。
描述你的代码和个人反思在脚本中使用comment关键字#允许您添加一个注释 解释器忽略。这使您可以向脚本添加更易于阅读的维度。ie。cp file123 directory20复制file123到目录20 #后面的文本没有添加任何功能,但解释了该命令的功能。评论你的描述它如何工作的脚本。最后,在您的脚本底部包含注释,即 反思部分(分为4个小节)是否a)一些个人的反思a)你的脚本的工作状态,b)你如何完成任务,c)你学到了什么 D)这将如何影响你在未来处理类似任务的方式。
总结:
-
工作目录 + 一个需要解压文件+脚本(接受三个参数) -
运行后 -
出现4个文件 jpg docx gif 和 others, 将源文件内容mv到各个文件 -
每个文件中有一个list, 排序保存每个文件夹内容(字母大小) -
当前工作目录里有个list保存倒叙储存所有内容 -
最后删除当前工作目录
Task2
开启一个服务, 配置ssh
在Ubuntu上安装和配置Apache Web Server。按照链接中的所有步骤操作
在Moodle上提供(如果你愿意,你可以使用不同的资源)。取一个截图
的每一个步骤。确保你的名字在截图中可见。当你设置好
您的域名,确保HTML文件包括标题消息,如
“欢迎来到编程与系统开发课程!”还要确保
在正文中包含一条信息,显示你的姓名和学号。
b)在Ubuntu系统上启用SSH。验证安装是否成功
SSH服务正在运行。再次强调,确保对每个步骤都进行截图
在你的文件。
上传
你必须上传一个压缩文件夹(your_name.zip,例如Mireilla_Bikanga_Ada.zip) 包含Moodle上的4个文件。第一个文件是你的主要脚本和个人反思 (process_files)。第二个文件是清理脚本(cleanup)。第三个文件是一个单词 包含截图的文件(your_name .docx,例如Mireilla_Bikanga_Ada1.docx) 当脚本运行时(Task 1) -显示目录和目录的内容 文件的内容。第四个文件是一个word文档(your_name .docx)。 Mireilla_Bikanga_Ada2.docx),包含Task 2的所有截图a)和b) 截图必须显示你的名字(见下面的例子)。
project_path=$(cd `dirname $0`; pwd)
project_name="${project_path##*/}"
echo $project_path
echo "delete${project_name}"
rm -r ../${project_name}
评分
-
A)解压文件,并为请求的每个文件类型和杂项创建目录 -
目录中。 -
B)文件类型的命令行参数的使用 -
C)将文件分离到相应的目录中。 -
D)提供每个目录中所有文件的列表,按大小5排序 -
E)提供一个有标签的汇总文件,将每个目录中的所有文件按字母倒序排序 -
F)提供一个单独的脚本来清理zip文件3中的所有文件 -
G)个人反思第四段 -
H)注释你的代码,解释这个过程 -
I)任务1的风格和演示 -
J)任务1的截图演示









SSH





lab
-
linux 严格区分大小写
-
linux只有文件和目录区别~目录就是文件夹
-
pwd 打印当前工作目录
-
ls打印目录
-
cd 进入操作
-
. / 进入根目录
-
cd /h tab 可以快速补全
cd /: 在Linux 系统中斜杠“/”表示的是根目录。cd / ,即进入根目录. cd ~命令是,进入用户在该系统的home目录,例如xz用户,则进入/root/xz目录。
-
ls p* 所有p开头文件 ls p*d所有 p开头d结尾文件 //pd 也算 文件夹会显示出所有内部文件 -
ls -d p* 只显示文件

part 2
-
Open a terminal and write down the current working directory -- pwd -
Switch to the root directory. Which command did you use --cd / -
How many files and directories in /etc end with the letter ‘p’ -- ls -d -l *p | wc -l -
How many files and directories in /etc end with the letter ‘f’ and contain a -- ls -d -l *a*f | wc -l -
Switch back to your home directory. What command did you use -- cd ~
touch 创建
cd .. 之类的用来相对定位
ls /dev 可以不进入目录打印目录内容
-
gedit touchtest.txt -
gedit touchtest.txt & -
echo Hello World > echotest.txt. 打印进入一个文件 -
mkdir testdirectory 创建目录 -
mv file_to_copy destination_directory. 移动 重命名 没有重命名 -
cp file_to_copy destination_directory 复制 没的话重新复制一个新名字的一样内容 -
rm echotest.txt 删除 -
rm –r directory_to_delete 删除文件夹 -
fallocate –l 150M bigfile.dat 创建一个150m的文件
part3
cat, head, tail, ps, kill, and man
-
cat 1.text -
cat 1.text 2.text -
cat 1.text 2.text > 3.text 写到 3里
ls /etc > test.txt 将返回值写到test.txt里
kill/ ps
ps 当前进程
kill 结束进程
kill -9 id 结束当前bash
man 查看
part4
(base) shinkai@pc-199-186 scripts % source ./helloworld
afsc_type5 ptyw7
auditpipe ptyw8
auditsessions ptyw9
autofs ptywa
autofs_control ptywb
autofs_homedirmounter ptywc
autofs_notrigger ptywd
autofs_nowait ptywe
bpf0 ptywf
bpf1 random
bpf2 rdisk0
bpf3 rdisk0s1
console rdisk0s2
cu.Bluetooth-Incoming-Port rdisk1
disk0 rdisk1s1
disk0s1 rdisk1s1s1
disk0s2 rdisk1s2
disk1 rdisk1s3
disk1s1 rdisk1s4
disk1s1s1 rdisk1s5
disk1s2 rdisk1s6
disk1s3 sdt
disk1s4 stderr
disk1s5 stdin
disk1s6 stdout
dtrace systrace
dtracehelper tty
fbt tty.Bluetooth-Incoming-Port
fd ttyp0
fsevents ttyp1
io8log ttyp2
io8logmt ttyp3
io8logtemp ttyp4
klog ttyp5
lockstat ttyp6
machtrace ttyp7
nsmb0 ttyp8
null ttyp9
oslog ttypa
oslog_stream ttypb
pf ttypc
pfm ttypd
profile ttype
ptmx ttypf
ptyp0 ttyq0
ptyp1 ttyq1
ptyp2 ttyq2
ptyp3 ttyq3
ptyp4 ttyq4
ptyp5 ttyq5
ptys2 ttyt0
ptys3 ttyt1
ptyw6
/dev
ld: warning: platform not specified
ld: warning: -arch not specified
ld: warning: No platform min-version specified on command line
ld: can't map file, errno=22 file '/etc' for architecture unknown
/etc
[ dd launchctl pwd test
bash df link rm unlink
cat echo ln rmdir wait4path
chmod ed ls sh zsh
cp expr mkdir sleep
csh hostname mv stty
dash kill pax sync
date ksh ps tcsh
/bin
(base) shinkai@pc-199-186 scripts % source ./helloworld
afsc_type5 ptyw7
auditpipe ptyw8
auditsessions ptyw9
autofs ptywa
autofs_control ptywb
autofs_homedirmounter ptywc
autofs_notrigger ptywd
autofs_nowait ptywe
bpf0 ptywf
bpf1 random
bpf2 rdisk0
bpf3 rdisk0s1
console rdisk0s2
cu.Bluetooth-Incoming-Port rdisk1
disk0 rdisk1s1
disk0s1 rdisk1s1s1
disk0s2 rdisk1s2
disk1 rdisk1s3
disk1s1 rdisk1s4
disk1s1s1 rdisk1s5
disk1s2 rdisk1s6
disk1s3 sdt
disk1s4 stderr
disk1s5 stdin
disk1s6 stdout
dtrace systrace
dtracehelper tty
fbt tty.Bluetooth-Incoming-Port
fd ttyp0
fsevents ttyp1
io8log ttyp2
io8logmt ttyp3
io8logtemp ttyp4
klog ttyp5
lockstat ttyp6
machtrace ttyp7
nsmb0 ttyp8
null ttyp9
oslog ttypa
oslog_stream ttypb
pf ttypc
pfm ttypd
profile ttype
ptmx ttypf
/dev
afpovertcp.cfg openldap
aliases pam.d
aliases.db passwd
apache2 paths
asl paths.d
asl.conf periodic
auto_home pf.anchors
auto_master pf.conf
autofs.conf pf.os
bashrc php-NOTICE-PLANNED-REMOVAL.txt
bashrc_Apple_Terminal php-fpm.conf.default
bootpd.plist php-fpm.d
com.apple.screensharing.agent.launchd php.ini
csh.cshrc php.ini.default
csh.login postfix
csh.logout ppp
cups profile
defaults protocols
emond.d racoon
find.codes rc.common
ftpusers rc.netboot
gettytab resolv.conf
group rmtab
hosts rpc
hosts.equiv rtadvd.conf
irbrc security
kern_loader.conf services
krb5.keytab shells
localtime snmp
locate.rc ssh
mail.rc ssl
man.conf sudo_lecture
manpaths sudoers
manpaths.d sudoers.d
master.passwd syslog.conf
nanorc ttys
networks uucp
newsyslog.conf wfs
newsyslog.d xtab
nfs.conf zprofile
notify.conf zshrc
ntp.conf zshrc_Apple_Terminal
ntp_opendirectory.conf
/etc
[ dd launchctl pwd test
bash df link rm unlink
cat echo ln rmdir wait4path
chmod ed ls sh zsh
cp expr mkdir sleep
csh hostname mv stty
dash kill pax sync
date ksh ps tcsh
/bin
(base) shinkai@pc-199-186 scripts % source ./helloworld
./helloworld:cd:4: no such file or directory: mkdir
(base) shinkai@pc-199-186 scripts % source ./helloworld
mkdir: mydir: File exists
./helloworld:cd:4: no such file or directory: mkdir
(base) shinkai@pc-199-186 scripts % ls
file1.txt file2.txt helloworld mydir outputthat
(base) shinkai@pc-199-186 scripts % rm *
zsh: sure you want to delete all 5 files in /Users/shinkai/Documents/programming system/TESTTEST/scripts [yn]? y
rm: mydir: is a directory
(base) shinkai@pc-199-186 scripts %
(base) shinkai@pc-199-186 scripts % source ./helloworld
source: no such file or directory: ./helloworld
(base) shinkai@pc-199-186 scripts % touch helloworld
(base) shinkai@pc-199-186 scripts % open helloworld
(base) shinkai@pc-199-186 scripts % ls
helloworld mydir
(base) shinkai@pc-199-186 scripts % rm -r mydir
(base) shinkai@pc-199-186 scripts % source ./helloworld
cat: file1.txt: No such file or directory
cat: file2.txt: No such file or directory
(base) shinkai@pc-199-186 mydir % ls
outputthat
(base) shinkai@pc-199-186 mydir % ls
outputthat
(base) shinkai@pc-199-186 mydir % cat outputthat
(base) shinkai@pc-199-186 mydir % source ./helloworld
source: no such file or directory: ./helloworld
(base) shinkai@pc-199-186 mydir % source ./helloworld
source: no such file or directory: ./helloworld
(base) shinkai@pc-199-186 mydir % source ./helloworld
source: no such file or directory: ./helloworld
(base) shinkai@pc-199-186 mydir % cd ..
(base) shinkai@pc-199-186 scripts % source ./helloworld
mkdir: mydir: File exists
(base) shinkai@pc-199-186 scripts % ls
file1.txt file2.txt helloworld mydir
(base) shinkai@pc-199-186 scripts % open mydir/outputthat
(base) shinkai@pc-199-186 scripts % source ./helloworld
rm: mydir: is a directory
./helloworld:2: command not found: y
./helloworld:4: command not found: y
(base) shinkai@pc-199-186 scripts % ls
helloworld
(base) shinkai@pc-199-186 scripts % ls
helloworld
(base) shinkai@pc-199-186 scripts % source ./helloworld
(base) shinkai@pc-199-186 scripts % source ./helloworld
source: no such file or directory: ./helloworld
(base) shinkai@pc-199-186 scripts % ls
(base) shinkai@pc-199-186 scripts % ls
(base) shinkai@pc-199-186 scripts % echo Enter three names
read FIRSTNAME SECONDNAME THIRDNAME
echo $THIRDNAME $SECONDNAME $FIRSTNAME
Enter three names
123
123
(base) shinkai@pc-199-186 scripts % echo Enter three names
Enter three names
(base) shinkai@pc-199-186 scripts % read FIRSTNAME SECONDNAME THIRDNAME
1
(base) shinkai@pc-199-186 scripts % echo $THIRDNAME $SECONDNAME $FIRSTNAME
1
(base) shinkai@pc-199-186 scripts % source ./helloworld
source: no such file or directory: ./helloworld
(base) shinkai@pc-199-186 scripts %
(base) shinkai@pc-199-186 scripts % ls
(base) shinkai@pc-199-186 scripts % touch hellowolrd
(base) shinkai@pc-199-186 scripts % open hellowolrd
(base) shinkai@pc-199-186 scripts % source ./hellowolrd
Enter three names
1
1
(base) shinkai@pc-199-186 scripts % source ./hellowolrd
Enter three names
Shinkai liudehua niubi
niubi liudehua Shinkai
(base) shinkai@pc-199-186 scripts % source ./hellowolrd
enter file name
niubi
niubi
enter file content
asdasda
cat: asdasda: No such file or directory
The file /Users/shinkai/Documents/programming system/TESTTEST/scripts/{FILENAME} does not exist.
(base) shinkai@pc-199-186 scripts % source ./hellowolrd
enter file name
niubi
niubi
enter file content
asdasdasdas
cat: asdasdasdas: No such file or directory
(base) shinkai@pc-199-186 scripts % ls
hellowolrd niubi
(base) shinkai@pc-199-186 scripts % open niubi
(base) shinkai@pc-199-186 scripts % cat "hello" > niubi
cat: hello: No such file or directory
(base) shinkai@pc-199-186 scripts % source ./hellowolrd
enter file name
niunn
niunn
enter file content
asdasdasdas
(base) shinkai@pc-199-186 scripts % open niunn
(base) shinkai@pc-199-186 scripts % source ./hellowolrd 666 你好么
./hellowolrd:1: command not found: FILENAME
./hellowolrd:2: command not found: FILECONTENT
niunn
(base) shinkai@pc-199-186 scripts % source ./hellowolrd 666 你好么
./hellowolrd:1: command not found: FILENAME
./hellowolrd:2: command not found: FILECONTENT
niunn
(base) shinkai@pc-199-186 scripts % source ./hellowolrd 1 2 3
1 2 3
(base) shinkai@pc-199-186 scripts % source ./hellowolrd 你好 你说 你谁
你好 你说 你谁
(base) shinkai@pc-199-186 scripts % source ./hellowolrd 你好 你说 你谁
你好
(base) shinkai@pc-199-186 scripts % ls
hellowolrd niubi niunn 你好
(base) shinkai@pc-199-186 scripts % source ./hellowolrd 你好
你好
(base) shinkai@pc-199-186 scripts % source ./hellowolrd 你好
- END -作者介绍
Shinkai005
公众号:深海笔记Shinkai