rmdir 刪除空目錄,非空的目錄不能刪除
1、命令格式
rmdir [options] DIRECTORY
2、命令參數
-p, 遞歸刪除,刪除目錄之前是否刪除父目錄,如果父目錄爲空的話就刪除
-v, 刪除目錄時,顯示刪除信息
--help 顯示此幫助信息並退出
--version 輸出版本信息並退出
3、常用範例
例1:刪除空目錄doc
命令:rmdir doc
[root@server~]# tree doc/ doc/ 0directories, 0 files [root@server~]# [root@server~]# ls anaconda-ks.cfg doc install.log install.log.syslog [root@server~]# rmdir doc/ [root@server~]# ls anaconda-ks.cfg install.log install.log.syslog [root@server~]#
例2:刪除非空目錄echo
命令:rmdir echo
[root@server~]# ls echo/ fstab [root@server~]# rmdir echo/ rmdir:failed to remove `echo/': Directory not empty [root@server~]#
提示:rmdir不能刪除非空的目錄,如果想刪除非空的目錄用rm -r命令 rm -r echo
[root@server~]# rm -r echo/ rm:descend into directory `echo'? y rm:remove regular file `echo/fstab'? y rm:remove directory `echo'? y [root@server~]#
例3:遞歸刪除目錄 tree1/tree2/tree3並顯示刪除過程
命令 rmdir -pv tree1/tree2/tree3
[root@server~]# tree tree1/ tree1/ └── tree2 └── tree3 2directories, 0 files [root@server~]# 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
root@server~]# 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 [root@server~]#
2、顯示/var/log目錄下的子目錄,以樹狀展現
命令:tree -d /var/log
[root@server~]# tree -d /var/log/ /var/log/ ├── audit ├── ConsoleKit ├── cups ├── ntpstats ├── prelink ├── sa ├── samba │ └── old └── sssd 9directories [root@server~]#
tree安裝方式,以CentOS6.5爲例
[root@server~]# mv /etc/yum.repos.d/* /bak/ //移動yum源倉庫的所有文件 到/bak目錄下 [root@server~]# cp /bak/CentOS-Media.repo /etc/yum.repos.d/ //把/bak下的e本地yum源倉庫(CentOS_Media.repo)複製一份到yum源倉庫 [root@server~]# vim /etc/yum.repos.d/CentOS-Media.repo //用vim編輯器編輯yum源(CentOS-Media.repo) #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 //在此將0修改爲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目錄中
[root@server~]# mount /dev/cdrom /media/cdrom/ //掛載光盤至/media/cdrom目錄下 mount:block device /dev/sr0 is write-protected, mounting read-only [root@server~]# 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) [root@server~]# yum -y install tree //安裝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! [root@server~]#
以上tree命令安裝成功