• 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

How to Create a New Directory in Linux

by admin

You can use the “mkdir” command to create new directories in Linux. Creating a new directory in Linux is easy — just use the mkdir command:

$ mkdir New_Dir
$ ls -ld New_Dir
drwxrwxr-x. 2 geek geek 21 Mar  6 14:40 New_Dir
$

The system creates a new directory named New_Dir . Notice in the new directory’s long listing that the directory’s record begins with a d . This indicates that New_Dir is a directory.

Occasionally, you may need to create directories and subdirectories in “bulk.” To do this, add the -p option to the mkdir command as shown here:

$ mkdir -p New_Dir/SubDir/UnderDir
$ ls -R New_Dir
New_Dir:
SubDir
 
New_Dir/SubDir:
UnderDir
 
New_Dir/SubDir/UnderDir:
$

The -p option on the mkdir command makes any missing parent directories as needed. A parent directory is a directory that contains other directories at the next level down the directory tree.

mkdir Examples

1. Create directory with specified octal permissions.

# mkdir -m750 [dirname]

By default, your shell’s umask controls the permissions.

2. Set SELinux security context of each created directory to the default type.

# mkdir -Z

3. Given a directory path (not just a simple directory name), create any necessary parent directories automatically.

# mkdir -p /one/two/three

Creates the directories /one and /one/two if they don’t already exist, then /one/two/three.

You can learn more about the mkdir command and its options on its man pages. Type man mkdir and press return to view the command’s man pages.

# man mkdir

Filed Under: Linux

Some more articles you might also be interested in …

  1. “VDO Status: Out of space” – Error while creating a VDO disk
  2. edquota: command not found
  3. How to setup passwordless SSH login in Linux
  4. fstrim Command Examples in Linux
  5. apt-add-repository Command Examples
  6. resolvectl: command not found
  7. cryptsetup: command not found
  8. Xtreme Download Manager(xdman): Internet Download Manager(IDM) For Ubuntu
  9. CentOS / RHEL : How to change password hashing algorithm
  10. mkfs.exfat: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • aws ec2: CLI for AWS EC2 (Command Examples)
  • aws cur – Create, query, and delete AWS usage report definitions (Command Examples)
  • aws configure – Manage configuration for the AWS CLI (Command Examples)
  • aws cognito-idp: Manage Amazon Cognito user pool and its users and groups using the CLI

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright