[Acwing Linux基础课] 第一讲の作业
homework_0:在 homework_0 下创建三个目录 dir_a, dir_b, dir_c
cd homework/lesson_1/homework_0
mkdir dir_{a..c}
homework_1:将a.txt, b.txt, c.txt 分别复制为 a.txt.bak, b.txt.bak, c.txt.bak
法一
cd ~/homework/lesson_1/homework_1
cp a.txt a.txt.bak
cp b.txt b.txt.bak
cp c.txt c.txt.bak
法二
cd ~/homework/lesson_1/homework_1
for var in *
do
cp "$var" "${var%.txt}.txt.bak"
done
homework_2:将a.txt, b.txt, c.txt 重命名为 a_new.txt, b_new.txt, c_new.txt
法一
cd ~/homework/lesson_1/homework_2
mv a.txt a_new.txt
mv b.txt b_new.txt
mv c.txt c_new.txt
法二
cd ~/homework/lesson_1/homework_2
for var in *
do
mv "$var" "${var%.txt}_new.txt"
done
homework_3:将dir a文件夹下的a.txt, b.txt,c.txt分别移动到文件夹dir b下
法一
cd ~/homework/lesson_1/homework_3
mv dir_a/a.txt dir_b
mv dir_a/b.txt dir_b
mv dir_a/c.txt dir_b
法二
cd ~/homework/lesson_1/homework_3
mv dir_a/* dir_b
homework_4:将普通文件a.txt,b.txt,c.txt删除
cd ~/homework/lesson_1/homework_4
rm a.txt b.txt c.txt
homework_5:将文件夹dir a, dir b, dir c删除
cd ~/homework/lesson_1/homework_5
rm dir_a dir_b dir_c _r
homework_6:查看task.txt的内容,并按其指示进行操作
cd ~/homework/lesson_1/homework_6
cat task.txt // 查看内容
mv task.txt done.txt // 重命名为 done.txt
mkdir dir_a // 创建目录 dir_a
mv done.txt dir_a/done.txt // 移动done.txt
homework_7:创建文件夹dir 0, dir 1, dir 2,将a.txt,b.txt,c.txt复制到dir_0下,重命名为a0.txt,b0.txt,c0.txt;将a.txt,b.txt,c.txt复制到dir_1下,重命名为a1.txt,b1.txt,cl.txt;将a.txt,b.txt,c.txt复制到dir_2下,重命名为a2.txt, b2.txt,c2.txt
法一:在复制的同时重命名
cd ~/homework/lesson_1/homework_7
mkdir dir_0 dir_1 dir_2
cp a.txt dir_0/a0.txt
cp b.txt dir_0/b0.txt
cp c.txt dir_0/c0.txt
cp a.txt dir_1/a1.txt
cp b.txt dir_1/b1.txt
cp c.txt dir_1/c1.txt
cp a.txt dir_2/a2.txt
cp b.txt dir_2/b2.txt
cp c.txt dir_2/c2.txt
法二
cd ~/homework/lesson_1/homework_7
for i in {0..2}
do
mkdir "dir_$i"
for var in *.txt
do
cp "$var" "dir_$i/${var%.txt}$i.txt"
done
done
homework_8:分别在dir a, dir b, dir c文件夹下查看task.txt的内容,并分别按照指示进行操作
cd ../homework_8
cd dir_a
cat task.txt // 要求把 a.txt 删除
rm a.txt
cd ../
cd dir_b
cat task.txt // 要求重命名 b.txt
mv b.txt b_new.txt
cd ../
cd dir_c
cat task.txt // 要求复制 c.txt
cp c.txt c.txt.bak
homework_9:将其中所有txt类型的文件删除
cd ~/homework/lesson_1/homework_9
rm *.txt
本文来自博客园,作者:泥烟,CSDN同名, 转载请注明原文链接:https://www.cnblogs.com/Knight02/p/15799126.html