linux命令(mkdir,rm ,rmdir)
4,mkdir 命令
功能 :用来创建指定的名称的目录或文件夹
要创建文件夹或目录的用户必须对所创建的文件夹的父文件夹具有写权限
mkdir test 创建test空目录 默认755权限
-m 设置模式权限
-p 递归创建一系列目录,路径中某些目录不存在
-v 创建新目录都显示信息
ligang@centos6 ~]$ rm -rf test [ligang@centos6 ~]$ mkdir -v test mkdir: created directory `test' [ligang@centos6 ~]$ mkdir -m 755 test1 [ligang@centos6 ~]$ ll test1 total 0 [ligang@centos6 ~]$ mkdir -p test/test1/test2 [ligang@centos6 ~]$ cd test [ligang@centos6 test]$ ll total 4 drwxr-xr-x 3 ligang trainning 4096 Mar 8 22:07 test1
5,rm命令
功能 :删除文件或文件夹
没有使用- r选项,则rm不会删除目录
rm 文件
-f, --force 忽略不存在的文件,从不给出提示。
-i, --interactive 进行交互式删除
-r, -R, --recursive 指示rm将参数中列出的全部目录和子目录均递归地删除。
[ligang@centos6 ~]$ mkdir test [ligang@centos6 ~]$ cd test [ligang@centos6 test]$ mkdir test1 [ligang@centos6 test]$ ll total 4 drwxr-xr-x 2 ligang trainning 4096 Mar 8 21:35 test1 [ligang@centos6 test]$ cd test1/ [ligang@centos6 test1]$ touch log{1..3}.log [ligang@centos6 test1]$ ll total 0 -rw-r--r-- 1 ligang trainning 0 Mar 8 21:37 log1.log -rw-r--r-- 1 ligang trainning 0 Mar 8 21:37 log2.log -rw-r--r-- 1 ligang trainning 0 Mar 8 21:37 log3.log
ligang@centos6 test]$ rm -f test1/ rm: cannot remove `test1/': Is a directory [ligang@centos6 test]$ cd test1/ [ligang@centos6 test1]$ rm -f log1.log [ligang@centos6 test1]$ rm -i log* rm: remove regular empty file `log2.log'? y rm: remove regular empty file `log3.log'? n [ligang@centos6 test1]$ ll total 0 -rw-r--r-- 1 ligang trainning 0 Mar 8 21:37 log3.log
[ligang@centos6 test]$ ll total 4 -rw-r--r-- 1 ligang trainning 0 Mar 8 21:57 1.log -rw-r--r-- 1 ligang trainning 0 Mar 8 21:57 2.log -rw-r--r-- 1 ligang trainning 0 Mar 8 21:57 3.log drwxr-xr-x 2 ligang trainning 4096 Mar 8 21:40 test1 [ligang@centos6 test]$ ll test1 total 0 -rw-r--r-- 1 ligang trainning 0 Mar 8 21:37 log3.log [ligang@centos6 test]$ rm -rf test1/ [ligang@centos6 test]$ ll total 0 -rw-r--r-- 1 ligang trainning 0 Mar 8 21:57 1.log -rw-r--r-- 1 ligang trainning 0 Mar 8 21:57 2.log -rw-r--r-- 1 ligang trainning 0 Mar 8 21:57 3.log
定义回收站功能
myrm(){ D=/tmp/$(date +%Y%m%d%H%M%S); mkdir -p $D; mv "$@" $D && echo "moved to $D ok"; }
模拟回收站的效果,即删除文件的时候只是把文件放到一个临时目录中,这样在需要的时候还可以恢复过来。
参考博客:
6,rmdir命令
功能:删除空目录
删除某目录是对父目录有写权限
-p 递归删除子目录及父目录为空时一并删除
[ligang@centos6 ~]$ tree test test ©¸©¤©¤ test1 ©¸©¤©¤ l.log 1 directory, 1 file [ligang@centos6 ~]$ mkdir test/test1/test2 [ligang@centos6 ~]$ tree test test ©¸©¤©¤ test1 ©À©¤©¤ l.log ©¸©¤©¤ test2 2 directories, 1 file [ligang@centos6 ~]$ rmdir test/test1/test2/ [ligang@centos6 ~]$ tree test test ©¸©¤©¤ test1 ©¸©¤©¤ l.log 1 directory, 1 file [ligang@centos6 ~]$ rm -f test/test1/l.log [ligang@centos6 ~]$ tree test test ©¸©¤©¤ test1 1 directory, 0 files [ligang@centos6 ~]$ mkdir test/test1/test2 [ligang@centos6 ~]$ rmdir -p test/test1/test2/ [ligang@centos6 ~]$ ls a.out crosstool-ng-1.16.0 goodbye.c signal.c apue crosstool-ng-centos-LingYun-v1.0.0.bin io.c study.c apue_test c_study log study_static b.c dynamic main.c test1 build.sh fl2440 rootfs-ubifs.bin test4 [ligang@centos6 ~]$ ll test ls: cannot access test: No such file or directory