有关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
推荐阅读:杭州汽车网
-
Cindy都瘦出了马甲线,你还要继续放纵吗?
各位,国庆都玩好睡好吃好了没?上班第一天,坛子先来给大家打一针鸡血。认得出来这是谁吗?不看脸,是不是都不敢相信这是3unshine组合的Cindy女士。来康康这...
2019-10-09 -
苹果越来越好色了,库克路子真野
AirPods(包括初代和第二代)的做工算不上好,价格也不够实惠,但由于独领风骚的设计和良好的连接性,使得它顺理成章地成为了最受欢迎的iPhone配件,同时也是...
2019-10-09 -
18岁女儿还和父亲同床,跨越界限的亲情,对孩
无论是友情还是亲情,都需要界限,一旦超越了界限,那么便会带来一些让人烦扰的隐患,特别是父女间,更要有界限。这种距离并不是说让父女间像陌生人一般相处,而是关系可以...
2019-10-09 -
美国辣妈为孩子拼尽脑洞 全手工万圣节服装也太
2019年10月7日报道(摄于10月2日),别闹了,这些服装赢了万圣节! 来自美国俄亥俄州的辣妈 Stephanie Pokorny 为她的孩子们创作了令人瞠目...
2019-10-09 -
iPhone 11又翻车!屏幕并不防刮擦;小
各位早上好,小米卖断货的巨能写终于现货了,你买吗?1,荣耀年末旗舰曝光:6000万四摄+40W快充+5G网络9月初,荣耀正式公布了Vera30新品,该机将打造麒...
2019-10-09 -
匡威这次赔大了!信心满满打造的中国风新品,却
不知道从什么时候开始,脚下的converse就不再仅仅是一双鞋子那么简单了!早就已经成为潮流的象征,是街头的时尚,潮流的符号在如今跟风AJ球鞋的时代,人们对于这...
2019-10-09 -
国庆加班就辞职,这届职场新人怎么了?
国庆长假刚结束,有人累觉不爱地回归工作岗位,翻开日历,发现一个激动人心的“好消息”,全国人民已经一起过完了2019所有法定节假日。不过,对于浙江义乌的某姑娘来说...
2019-10-09 -
2019年动漫展在纽约举行 超级英雄成最大亮
当地时间2019年10月7日,美国纽约,2019年动漫展在纽约雅各布·k·贾维茨会议中心举行,参加动漫展的人穿着戏服摆pose,现场十分热闹。当地时间2019年...
2019-10-09