您所在的位置: > 主页 > 大众创业网 > 科技 > 正文
linux基础篇7——linux基础篇1~6的命令总结与练习来源: 日期:2020-09-21 11:36:20  阅读:-

    linux基础篇7——linux基础篇1~6的命令总结与练习

    有关touch命令

    touch命令有两个作用,如果参数文件存在,则是更新文件的访问时间。如果文件不存在 ,则创建新文件。

    下面是之前linux基础篇1~6的总结与练习。

    在家目录中,创建6个以songX.mp3命名的文件,创建6个以snapX.jpg命名的文件,创建6个以filmX.avi命名的文件。X替换为数字1到6。

    [root@laoda ~]# touch song1.mp3 song2.mp3 song3.mp3 song4.mp3 song5.mp3 song6.mp3

    [root@laoda ~]# touch snap1.jpg snap2.jpg snap3.jpg snap4.jpg snap5.jpg snap6.jpg

    [root@laoda ~]# touch file1.avi file2.avi file3.avi file4.avi file5.avi file6.avi

    [root@laoda ~]# ls -l

    在家目录中,将歌曲文件移动到Music子目录中,将快照文件移动到Pictures子目录中,将影片文件移动到Videos子目录中

    [root@laoda ~]# mv song1.mp3 song2.mp3 song3.mp3 song4.mp3 song5.mp3 song6.mp3 Music

    [root@laoda ~]# mv snap1.jpg snap2.jpg snap3.jpg snap4.jpg snap5.jpg snap6.jpg Pictures

    [root@laoda ~]# mv file1.avi file2.avi file3.avi file4.avi file5.avi file6.avi Videos

    [root@laoda ~]# ls -l Music Pictures Videos

    在家目录中,创建3个子目录。

    [root@laoda ~]# mkdir friends family work

    [root@laoda ~]# ls -l

    将编号为1和2的文件(所有类型)复制到friends目录。将编号为3和4的文件(所有类型)复制到family目录

    [root@laoda ~]# cd friends

    [root@laoda friends]# cp ~/Music/song1.mp3 ~/Music/song2.mp3 ~/Pictures/snap1.jpg ~/Pictures/snap2.jpg ~/Videos/film1.avi .

    [root@laoda friends]# ls -l

    [root@laoda friends]# cd ../family

    [root@laoda family]# cp ~/Music/song3.mp3 ~/Music/song4.mp3 ~/Pictures/snap3.jpg ~/Pictures/snap4.jpg ~/Videos/film3.avi ~/Videos/film4.avi .

    [root@laoda family]# ls -l

    进入work目录,创建额外的副本

    [root@laoda family]# cd ../work

    [root@laoda work]# cp ~/Music/song5.mp3 ~/Music/song6.mp3 ~/Pictures/snap5.jpg ~/Pictures/snap6.jpg ~/Videos/film5.avi ~/Videos/film6.avi .

    [root@laoda work]# ls -l

    返回家目录,尝试使用rmdir命令同时删除family和friends目录

    [root@laoda work]# cd

    [root@laoda ~]# rmdir family friends

    使用rm命令删除family和friends目录

    [root@laoda ~]# rm -r family friends

    [root@laoda ~]# ls -l

    删除work目录中的所有文件,但不要删除work目录本身

    [root@laoda ~]# cd work

    [root@laoda work]# rm song5.mp3 song6.mp3 snap5.jpg snap6.jpg film5.avi film6.avi

    [root@laoda work]# ls -l

    返回家目录,使用rmdir命令删除work目录。

    [root@laoda work]# cd

    [root@laoda ~]# rmdir work

    [root@laoda ~]# ls -l

    创建12个文件为名称为tv_seasonX_episodeY.ogg。X为season号码,Y为episode号码,6个episode,每个episode2个season。

    [root@laoda ~]# touch tv_season{1..2}_episode{1..6}.ogg

    [root@laoda ~]# ls -l

    创建8个文件,名称为mystery_chapterX.odf。使用数字1到8替换X。

    [root@laoda ~]# touch mystery_chapter{1..8}.odf

    [root@laoda ~]# ls -l

    在Videos下创建2个子目录,名称为season1和season2。

    [root@laoda ~]# mkdir Videos/season{1..2}

    [root@laoda ~]# ls -lR

    移动适当的TV episode到season子目录。

    [root@laoda ~]# mv tv_season1* Videos/season1

    [root@laoda ~]# mv tv_season2* Videos/season2

    [root@laoda ~]# ls -lR

    使用一条命令创建一个两级目录层次结构,在Document下创建my_bestseller,my_bestseller下面创建chapters。

    [root@laoda ~]# mkdir -p Documents/my_bestseller/chapters

    [root@laoda ~]# ls -lR

    在my_bestseller目录下创建三个子目录,名称为editor,plot_change,vacation。

    [root@laoda ~]# mkdir Documents/my_bestseller/{editor,plot_change,vacation}

    [root@laoda ~]# ls -lR

    进入chapters目录。使用家目录快捷方式来指定源文件,移动所有chpters到chapters目录

    [root@laoda ~]# cd Documents/my_bestseller/chapters

    [root@laoda chapters]# mv ~/mystery_chapter* .

    [root@laoda chapters]# ls -l

    从chapters子目录仅移动起始的2个chapters到editor目录。

    [root@laoda chapters]# mv mystery_chapter1.odf mystery_chapter2.odf ../editor

    [root@laoda chapters]# ls -l

    [root@laoda chapters]# ls -l ../editor

    从chapters移动chapters7和8到vacation。

    [root@laoda chapters]# mv mystory_chpter7.odf mystery_chapter8.odf ../vacation

    [root@laoda chapters]# ls -l

    [root@laoda chapters]# ls -l ../vacation

    更改工作目录到season 2 TV episodes,然后拷贝season的第一个episode到vacation目录。

    [root@laoda chapters]# cd ~/Videos/season2

    [root@laoda season2]# cp tv_season2_episode1.ogg ~/Documents/my_bestseller/vacation

    更改工作目录到vacation,然后列出文件。使用当前工作目录快捷方式返回season2。拷贝episode2到vacation。再次使用快捷方式返回vacation。

    [root@laoda season2]# cd ~/Documents/my_bestseller/vacation

    [root@laoda vacation]# ls -l

    [root@laoda vacation]# cd -

    [root@laoda season2]# cp tv_season2_episode2.ogg ~/Documents/my_bestseller/vacation

    [root@laoda vacation]# cd -

    [root@laoda vacation]# ls -l

    移动到vacation的父目录,拷贝chapters5和6到plot_change.

    [root@laoda vacation]# cd ..

    [root@laoda my_bestseller]# cd chapters/mystery_chapter[56].odf plot_change

    [root@laoda my_bestseller]# ls -l chapters

    [root@laoda my_bestseller]# ls -l plot_change

    进入plot_change目录,创建chapter 5的三个备份。一个文件名包含完成日期。一个附加当前时间戳。一个附加当前用户

    [root@laoda my_bestseller]# cd plot_change

    [root@laoda plot_change]# cp mystery_chapter5.odf mystery_chapter5_$(date +%F).odf

    [root@laoda plot_change]# cp mystery_chapter5.odf mystery_chapter5_$(date +%s).odf

    [root@laoda plot_change]# cp mystery_chapter5.odf mystery_chapter5_$USER.odf

    [root@laoda plot_change]# ls -l

    删除plot_change目录中的所有文件。改变目录到上一级,因为当它是正在工作的目录时目录不能删除。使用rm不带递归选项删除目录,失败。使用rmdir命令,成功。

    [root@laoda plot_change]# rm mystery*

    [root@laoda plot_change]# cd ..

    [root@laoda my_bestseller]# rm plot_change

    rm: cannot remove 'plot_change': Is a directory

    [root@laoda my_bestseller]# rmdir plot_change

    [root@laoda my_bestseller]# ls -l

    使用带递归选项的rm命令删除vacation目录

    [root@laoda my_bestseller]# rm -r vacation

    [root@laoda my_bestseller]# ls -l

    [root@laoda my_bestseller]# cd

    (正文已结束)

    免责声明及提醒:此文内容为本网所转载企业宣传资讯,该相关信息仅为宣传及传递更多信息之目的,不代表本网站观点,文章真实性请浏览者慎重核实!任何投资加盟均有风险,提醒广大民众投资需谨慎!