리눅스에서 디렉토리 생성과 삭제 명령어 mkdir, rmdir

리눅스에서 디렉토리 생성과 삭제 명령어 mkdir, rmdir

[root@localhost ~]# mkdir test
디렉토리 생성

[root@localhost ~]# mkdir -p test2/test3
서브 디렉토리까지 함께 생성 옵션

[root@localhost ~]# ls
Desktop  anaconda-ks.cfg  install.log  install.log.syslog  scsrun.log  test  test2
[root@localhost ~]# rmdir test
디렉토리 삭제  - 빈 디렉토리만 삭제가능

[root@localhost ~]# rmdir -p test2/test3
서브 디렉토리 까지 삭제 - 비어있어야 함

[root@localhost ~]# ls
Desktop  anaconda-ks.cfg  install.log  install.log.syslog  scsrun.log
[root@localhost ~]# mkdir test
[root@localhost ~]# ll
total 64
drwxr-xr-x 2 root root  4096 Oct  5 07:41 Desktop
-rw------- 1 root root  1210 Oct  5 07:30 anaconda-ks.cfg
-rw-r--r-- 1 root root 27415 Oct  5 07:30 install.log
-rw-r--r-- 1 root root  3738 Oct  5 07:30 install.log.syslog
-rw-r--r-- 1 root root   199 Oct  5 07:38 scsrun.log
drwxr-xr-x 2 root root  4096 Oct  5 08:53 test
디렉토리 생성 시 퍼미션 까지 지정하는 옵션
[root@localhost ~]# rmdir test
[root@localhost ~]# mkdir -m test
mkdir: missing operand
Try `mkdir --help' for more information.
[root@localhost ~]# mkdir -m 777 test
퍼미션을 777로 주고 생성하는 샘플

[root@localhost ~]# ll
total 64
drwxr-xr-x 2 root root  4096 Oct  5 07:41 Desktop
-rw------- 1 root root  1210 Oct  5 07:30 anaconda-ks.cfg
-rw-r--r-- 1 root root 27415 Oct  5 07:30 install.log
-rw-r--r-- 1 root root  3738 Oct  5 07:30 install.log.syslog
-rw-r--r-- 1 root root   199 Oct  5 07:38 scsrun.log
drwxrwxrwx 2 root root  4096 Oct  5 08:54 test
[root@localhost ~]#


파일이 있는 디렉토리 삭제는

rm -rf 디렉토리명 
이렇게 삭제하면 됩니다.



[root@localhost ~]# mkdir --help
Usage: mkdir [OPTION] DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.
  -m, --mode=MODE   set permission mode (as in chmod), not rwxrwxrwx - umask
  -p, --parents     no error if existing, make parent directories as needed
  -v, --verbose     print a message for each created directory
  -Z, --context=CONTEXT (SELinux) set security context to CONTEXT
      --help     display this help and exit
      --version  output version information and exit

Report bugs to <bug-coreutils@gnu.org>.
[root@localhost ~]#





[root@localhost ~]# rmdir --help
Usage: rmdir [OPTION]... DIRECTORY...
Remove the DIRECTORY(ies), if they are empty.

      --ignore-fail-on-non-empty
                  ignore each failure that is solely because a directory
                  is non-empty
  -p, --parents   Remove DIRECTORY and its ancestors.  E.g., `rmdir -p a/b/c' is
                  similar to `rmdir a/b/c a/b a'.
  -v, --verbose   output a diagnostic for every directory processed
      --help     display this help and exit
      --version  output version information and exit

Report bugs to <bug-coreutils@gnu.org>.
[root@localhost ~]#