一天一个Linux基础命令之目录管理类命令rmdir
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一天一个Linux基础命令之目录管理类命令rmdir相关的知识,希望对你有一定的参考价值。
rmdir 删除空目录,非空的目录不能删除
1、命令格式
rmdir [options] DIRECTORY
2、命令参数
-p, 递归删除,删除目录之前是否删除父目录,如果父目录为空的话就删除
-v, 删除目录时,显示删除信息
--help 显示此帮助信息并退出
--version 输出版本信息并退出
3、常用范例
例1:删除空目录doc
命令:rmdir doc
[[email protected]~]# tree doc/ doc/ 0directories, 0 files [[email protected]~]# [[email protected]~]# ls anaconda-ks.cfg doc install.log install.log.syslog [[email protected]~]# rmdir doc/ [[email protected]~]# ls anaconda-ks.cfg install.log install.log.syslog [[email protected]~]#
例2:删除非空目录echo
命令:rmdir echo
[[email protected]~]# ls echo/ fstab [[email protected]~]# rmdir echo/ rmdir:failed to remove `echo/‘: Directory not empty [[email protected]~]#
提示:rmdir不能删除非空的目录,如果想删除非空的目录用rm -r命令 rm -r echo
[[email protected]~]# rm -r echo/ rm:descend into directory `echo‘? y rm:remove regular file `echo/fstab‘? y rm:remove directory `echo‘? y [[email protected]~]#
例3:递归删除目录 tree1/tree2/tree3并显示删除过程
命令 rmdir -pv tree1/tree2/tree3
[[email protected]~]# tree tree1/ tree1/ └── tree2 └── tree3 2directories, 0 files [[email protected]~]# rmdir -pv tree1/tree2/tree3/ rmdir:removing directory, `tree1/tree2/tree3/‘ rmdir:removing directory, `tree1/tree2‘ rmdir:removing directory, `tree1‘
扩展:
tree命令:以树状图列出文件目录结构。Centos6.5没有tree命令,需要手动安装,下面介绍tree命令的安装方法
1、命令格式:
tree [options] DIRECTORY
2、常用参数
-d:生成目录树的时候只显示目录
3、使用范例
1、显示/var/log下的文件,以树状形式展现
命令:tree /var/log
[email protected]~]# tree /var/log/ /var/log/ ├── anaconda.ifcfg.log ├── anaconda.log ├── anaconda.program.log ├── anaconda.storage.log ├── anaconda.syslog ├── anaconda.xlog ├── anaconda.yum.log ├── audit │ └── audit.log ├── boot.log ├── btmp ├── ConsoleKit │ └── history ├── cron ├── cups ├── dmesg ├── dmesg.old ├── dracut.log ├── lastlog ├── maillog ├── mcelog ├── messages ├── ntpstats ├── prelink │ └── prelink.log ├── sa │ ├── sa07 │ └── sa08 ├── samba │ └── old ├── secure ├── spooler ├── sssd ├── tallylog ├── wtmp └── yum.log 9directories, 27 files [[email protected]~]#
2、显示/var/log目录下的子目录,以树状展现
命令:tree -d /var/log
[[email protected]~]# tree -d /var/log/ /var/log/ ├── audit ├── ConsoleKit ├── cups ├── ntpstats ├── prelink ├── sa ├── samba │ └── old └── sssd 9directories [[email protected]~]#
tree安装方式,以CentOS为例
[[email protected]~]# mv /etc/yum.repos.d/* /bak/ 移动yum源仓库的所有文件 到/bak目录下 [[email protected]~]# cp /bak/CentOS-Media.repo /etc/yum.repos.d/ 把/bak下的e本地yum源仓库(CentOS_Media.repo)复制一份到yum源仓库 [[email protected]~]# vim /etc/yum.repos.d/CentOS-Media.repo 用vim编辑器编辑yum源 #CentOS-Media.repo # # This repo can be used with mounted DVD media,verify the mount point for # CentOS-6. You can use this repo and yum to install items directly off the # DVD ISO that we release. # # To usethis repo, put in your DVD and use it with the other repos too: # yum --enablerepo=c6-media [command] # # or forONLY the media repo, do this: # # yum --disablerepo=\* --enablerepo=c6-media[command] [c6-media] name=CentOS-$releasever- Media baseurl=file:///media/CentOS/ file:///media/cdrom/ file:///media/cdrecorder/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
提示:默认CentOS-Media.repo没有开启这个软件仓库固在郁闷源里面查找不到此源,需把enabled从0改到1开启 0是关闭状态,1是开启
链接cdrom把CentOS6.5的安装光盘插入然后挂载至上面四个目录中的某一个即可
以下我挂载到/media下的cdrom目录中
[[email protected]~]# mount /dev/cdrom /media/cdrom/ mount:block device /dev/sr0 is write-protected, mounting read-only [[email protected]~]# mount /dev/mapper/vg_server-LogVol00on / type ext4 (rw) proc on/proc type proc (rw) sysfs on/sys type sysfs (rw) devpts on/dev/pts type devpts (rw,gid=5,mode=620) tmpfs on/dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") /dev/sda1on /boot type ext4 (rw) /dev/mapper/vg_server-LogVol02on /home type ext4 (rw) none on/proc/sys/fs/binfmt_misc type binfmt_misc (rw) /dev/sr0 on /media/cdrom type iso9660 (ro) [[email protected]~]# yum -y install tree Loadedplugins: fastestmirror, security Loadingmirror speeds from cached hostfile * c6-media: Settingup Install Process ResolvingDependencies --> Runningtransaction check --->Package tree.x86_64 0:1.5.3-2.el6 will be installed -->Finished Dependency Resolution DependenciesResolved ================================================================================================================================== Package Arch Version Repository Size ================================================================================================================================== Installing: tree x86_64 1.5.3-2.el6 c6-media 36 k TransactionSummary ================================================================================================================================== Install 1 Package(s) Totaldownload size: 36 k Installedsize: 65 k DownloadingPackages: Runningrpm_check_debug RunningTransaction Test TransactionTest Succeeded RunningTransaction Installing : tree-1.5.3-2.el6.x86_64 1/1 Verifying : tree-1.5.3-2.el6.x86_64 1/1 Installed: tree.x86_64 0:1.5.3-2.el6 Complete! [[email protected]~]#
以上tree命令安装成功
本文出自 “linux菜鸟” 博客,请务必保留此出处http://geekb0y.blog.51cto.com/10743719/1880932
以上是关于一天一个Linux基础命令之目录管理类命令rmdir的主要内容,如果未能解决你的问题,请参考以下文章