CIS120 Linux Fundamentals by Scott Shaper

mkdir Command

Think of the mkdir command as your digital folder creator. Just like you create folders on your desktop to organize files, mkdir helps you create directories (folders) in Linux to keep your files organized.

Why Use mkdir?

You'll use mkdir when you want to:

Basic Usage

The simplest way to create a directory is:

mkdir directory_name

For example, to create a folder for your class notes:

mkdir class_notes

Common Options

Option What It Does When to Use It
-p Creates parent directories if they don't exist When creating nested folders
-v Shows what's being created When you want to see the process
-m Sets permissions for the new directory When you need specific access rights
-Z Sets SELinux security context When working with SELinux systems
--context Like -Z but specifies full context When you need specific SELinux settings
--mode Same as -m but more explicit When you want to be very clear about permissions
--parents Same as -p but more explicit When you want to be very clear about parent creation
--verbose Same as -v but more explicit When you want to be very clear about verbosity
--help Shows help information When you need to see all options
--version Shows version information When you need to check the version

Practical Examples

Creating a Single Directory

Let's create a folder for your project:

mkdir my_project

Creating Multiple Directories

You can create several folders at once:

mkdir notes homework projects

Creating Nested Directories

To create a folder inside another folder (even if the parent doesn't exist):

mkdir -p school/spring2024/cs101/assignments

Creating with Permissions

To create a directory with specific access rights:

mkdir -m 755 shared_folder

This creates a folder that you can read, write, and execute, while others can only read and execute.

Tips for Success

Common Mistakes to Avoid

Best Practices