• 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 configure DM-Multipath from an iSCSI initiator to an iSCSI target in CentOS / RHEL
  2. Beginners Guide to Tuning Profiles in CentOS/RHEL
  3. fprintd-enroll Command Examples in Linux
  4. “yum clean all” not clearing yum repository cache in CentOS/RHEL/OEL
  5. How to disable NFS client caching in CentOS/RHEL
  6. CentOS/RHEL : Unmounting a Windows Share Fails – “device is busy”
  7. rm: command not found
  8. su: command not found
  9. dnstracer Command Examples in Linux
  10. How to Configure Separate Port For SSH and SFTP On CentOS/RHEL

You May Also Like

Primary Sidebar

Recent Posts

  • qsub Command Examples in Linux
  • qsub: command not found
  • qrcp Command Examples in Linux
  • qmrestore Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright