您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > LINUX操作系统基础第三次操作命令
ITEducation&TrainingDate:1February2020上讲内容浏览目录命令:cd、pwd、ls、ll浏览文件命令:cat、tac、nl、more、less、head、tailITEducation&TrainingDate:1February2020上讲问题在linux下,如何能显示出/etc/man.config文件的第11行到第20行内容?(3分)ITEducation&TrainingDate:1February2020sed-n'11,20p'/etc/man.confighead-n20/etc/man.config|tail-n11ITEducation&TrainingDate:1February2020head-n20/etc/man.config|tail[root@teacher~]#head-n20/etc/man.confighead1[root@teacher~]#tailhead1ITEducation&TrainingDate:1February2020本讲内容目录操作命令:mkdir、rmdir文件操作命令:touch、rm、mv、cp、ln、tar、gzip、gunzip、whereis、whatisITEducation&TrainingDate:1February2020mkdir(建立新目录)如果想建立新目录,就使用mkdir(makedirectory,生成目录)。注意:在默认情况下,目录是要一层一层建立的。ITEducation&TrainingDate:1February2020参数-m:表示设置文件的权限,不管默认权限。(该功能命令后续课程会补充)参数-p:帮助目录用户直接建立所需要的递归。ITEducation&TrainingDate:1February2020mkdir实验cd/tmpls–almkdirtestls-almkdirtest1/test2/test3ls-alITEducation&TrainingDate:1February2020rmdir(删除“空”目录)空目录(emptydirectory)。rmdir(rmovedirectory,删除目录)。当然,它仅能“删除空的目录”参数-p,与上层空目录也一次删除。ITEducation&TrainingDate:1February2020rmdir实验cd/tmpls–alrmdirtestls–alrmdirtest1rmdirtest1/test2/test3ITEducation&TrainingDate:1February2020mkdirt1/t2/t3ls–alrmdir–pt1/t2/t3注意:没有加参数-p,rmdir只能一级一级删除空目录。ITEducation&TrainingDate:1February2020touch修改文件时间与创建新文件Modificationtime(mtime,修改时间):当该文件的“内容数据”更改时,就会更新这个时间,内容数据指的是文件的内容,而不是文件的属性。ITEducation&TrainingDate:1February2020Statustime(ctime,状态时间):当该文件的“状态(status)”改变时,就会更新这个时间,也即更改了权限与属性,就会更新这个时间。ITEducation&TrainingDate:1February2020Accesstime(atime,访问时间):当“读取文件内容”时,就会更新这个读取时间。例如,使用cat去读取某文件,就会更新atime了。ITEducation&TrainingDate:1February2020看看/etc/man.config文件的时间[root@teachertmp]#ls-l/etc/man.config-rw-r--r--1rootroot46172006-07-13/etc/man.config[root@teachertmp]#ls-l--time=atime/etc/man.config-rw-r--r--1rootroot461709-2911:14/etc/man.config[root@teachertmp]#ls-l--time=ctime/etc/man.config-rw-r--r--1rootroot461709-1121:12/etc/man.configITEducation&TrainingDate:1February2020touch参数参数-a,仅修改访问时间。参数-c,仅修改时间,而不建立文件。参数-d,后面直接加日期,也可以使用—date=“日期或时间”。参数-m,仅修改“修改时间”。ITEducation&TrainingDate:1February2020参数-t,后面可以接时间,格式为YYMMDDhhmm。常用情况是:建立一个空文件;修改文件的日期为当前日期。ITEducation&TrainingDate:1February2020touch实验cd/tmptouchtesttouchls-ltesttouchcptesttouchtesttouch1lltesttouch1;ll--time=atimetesttouch1;ll--time=ctimetesttouch1ITEducation&TrainingDate:1February2020touch-d2daysagotesttouch1lltesttouch1;ll--time=atimetesttouch1;ll--time=ctimetesttouch1ITEducation&TrainingDate:1February2020rm(删除文件或目录)请慎用该命令,该命令的操作可能对你的系统带来危害!删除命令(remove)相当于DOS下的del命令,默认参数-i,交互模式,在删除前会询问用户是否操作。ITEducation&TrainingDate:1February2020参数-f,就是force的意思,强制删除。参数-r,递归删除,常用在目录的删除。ITEducation&TrainingDate:1February2020rm实验[root@teachertmp]#cd/tmp[root@teachertmp]#touch123[root@teachertmp]#rm-i123rm:是否删除一般空文件“123”?n[root@teachertmp]#cd/test-bash:cd:/test:没有那个文件或目录[root@teachertmp]#mkdirtest[root@teachertmp]#cdtest/[root@teachertest]#touch123[root@teachertest]#cd..[root@teachertmp]#rmdirtestrmdir:test:目录非空[root@teachertmp]#rm-ftestrm:无法删除“test”:是一个目录[root@teachertmp]#rm-rftestITEducation&TrainingDate:1February2020mv(移动文件与目录,或重命名)mv是移动(move)的缩写,要移动文件与目录,或重命名可以使用mv。参数-f,force,强制的意思,强制直接移动而不询问。ITEducation&TrainingDate:1February2020参数-i,若目标文件(destination)已经存在,就会询问是否覆盖。参数-u,若目标文件已经存在,且源文件比较新,才会更新(update)ITEducation&TrainingDate:1February2020mv实验例题1:在/tmp下,复制一个文件,建立一个目录,将该文件移到目录中。答:cd/tmpcp~/.bashrcbashrcmkdirtest2mvbashrctest2(将文件bashrc移动到目录test2)ITEducation&TrainingDate:1February2020例题2:将test2文件重命名为testmv。(也即文件夹重命名)答:mvtest2testmv(大家可以manrename,并试试这个命令)ITEducation&TrainingDate:1February2020cp(复制文件或目录)要复制文件,或建立连接文件(快捷方式),请用cp(copy)命令。参数-a,相当于-pdr的意思参数-d,若源文件为连接文件的属性(linkfile),则复制连接文件属性而非文件本身。ITEducation&TrainingDate:1February2020参数-f,强制复制。参数-i,是否覆盖,交互模式。参数-l,建立硬连接(hardlink),而非复制文件本身。参数-p,与文件的属性一起复制,而非使用默认属性。ITEducation&TrainingDate:1February2020参数-r,递归持续复制,用于目录的复制操作。参数-s,复制成为“快捷方式”的连接文件(symboliclink)。参数-u,若目标文件比源文件旧,更新目标文件。ITEducation&TrainingDate:1February2020cp实验例题1:将家目录下的.bashrc复制到/tmp下,并重命名为bashrc。答:cd/tmpcp~/.bashrcbashrccp–i~/.bashrcbashrc(-i表示询问是否覆盖已存在的文件,-f表示不询问,直接覆盖。)ITEducation&TrainingDate:1February2020例题2:将/var/log/wtmp完整复制到/tmp下。答:cp–a/var/log/wtmp.(记住“.”,-a表示完整复制,不更改任何文件的参数。可以试试不加-a)ITEducation&TrainingDate:1February2020例题3:将/etc/目录下的所有内容复制到/tmp。答:cp–r/etc/.(记住“.”,-r表示目录复制,但文件与目录的权限会改变。可以试试不加-r)ITEducation&TrainingDate:1February2020例题4:将/tmp目录下的bashrc创建一个快捷方式(也叫符号连接symboliclink)答:cp–sbashrcbashrc_slink(需要加参数s)ITEducation&TrainingDate:1February2020例题5:将/tmp目录下的bashrc创建一个硬连接答:cp–lbashrcbashrc_hlink(需要加参数l)ITEducation&TrainingDate:1February2020例题6:若~/.bashrc比/tmp/bashrc新,则复制。(通常就是备份数据)答:cp–u~/.bashrc/tmp/bashrc(需要加参数u,表示update)ITEducation&TrainingDate:1February2020例题7:将例题4生成的bashrc_slink复制成bashrc_slink2答:cpbashrc_slinkbashrc_slink2(如果不加属性复制参数d或a,则是复制文件)ITEducation&TrainingDate:1February2020请各位同学认真做好实验。ITEducation&TrainingDate:1February2020未完待续………...ITEducation&TrainingDate:1February2020预祝各位国庆、中秋合家欢乐、万事如意!ITEducation&TrainingDate:1February202
本文标题:LINUX操作系统基础第三次操作命令
链接地址:https://www.777doc.com/doc-3396613 .html