• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

mkdir and rmdir Command Examples in Linux

by admin

The mkdir command is used to create (or make) a directory. You supply the name of the directory as an argument. The rmdir directory is used to remove directories, but only those that are empty (i.e., contain no files or subdirectories). In order to delete a directory with actual contents, you must use the rm -R command.

Syntax

The syntax of the mkdir and rmdir commands is:

# mkdir/rmdir {directory names}

mkdir Command Examples

1. To make the directory:

# mkdir mike 

2. To set file mode while making the directory:

# mkdir -m 
# mkdir --mode=MODE 

3. To make parent directories if needed:

# mkdir -p /support/mike
# mkdir --parents /support/mike 

4. To set to verbose mode:

# mkdir -v
# mkdir --verbose 

5. To set the SELinux security context of each created directory to CTX:

# mkdir -Z
# mkdir --context=CTX 

6. To get the help:

# mkdir --help 

7. To output the version information:

# mkdir --version 

rmdir Command Examples

1. To remove an empty directory:

# rmdir /mike 

2. To ignore each failure that is solely because a director:

# rmdir --ignore-fail-on-non-empty 

3. To remove DIRECTORY and its ancestors:

# rmdir -p /mike/mydir
# rmdir --parents /mike/mydir 

4. To output a diagnostic for every directory processed:

# rmdir -v /mike/mydir
# rmdir --verbose /mike/mydir 

5. To get the help:

# rmdir --help 

6. To get the version:

# rmdir --version

Filed Under: Linux

Some more articles you might also be interested in …

  1. How To Disable Ksplice Service on OEL
  2. What is the purpose of utmp, wtmp and btmp files in Linux
  3. Linux OS Service ‘NetworkManagerDispatcher’
  4. CentOS / RHEL 6 : Lock User Account After N Number of Incorrect Login Attempts
  5. What is the difference between the -i and -U options used in rpm command in Linux
  6. How to disable NFS client caching in CentOS/RHEL
  7. lsattr Command Examples in Linux
  8. “comm” Command in Linux with Examples
  9. How to add swap space in linux
  10. jpegoptim for image optimization

You May Also Like

Primary Sidebar

Recent Posts

  • What are /dev/zero and /dev/null files in Linux
  • grpck command – Remove corrupt or duplicate entries in the /etc/group and /etc/gshadow files.
  • xxd command – Expressed in hexadecimal form
  • sesearch: command not found

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright