Kali Linux

How to Create Directories in Linux with the mkdir Command

Creating directories is one of the earliest skills you’ll use on a Linux system. The mkdir (make directory) command provides a straightforward way to organize your files by creating folders wherever you need them, whether it’s one directory or an entire hierarchy in a single step. This guide walks you through mkdir usage, options, cautionary tips, and a range of practical, unique examples.

Basic Syntax

mkdir [options] directory_name

You can replace directory_name with any label you want for your new folder. Permissions for the parent location are required, otherwise you’ll receive a permission error.

Common mkdir Options

OptionDescription
-pCreate parent directories as needed (no errors if they already exist)
-mSet permissions for new directories at creation (e.g., 755 for rwxr-xr-x)
-vDisplay a message for every directory created (verbose)
–versionOutput version and license details
–helpShow help and available options
-ZSet SELinux security context for new directories (advanced/security environments)

Unique Examples for mkdir Command

1. Creating a Single Directory

mkdir workspace

Creates a folder named workspace in your current directory.

2. Making Multiple Directories in One Command

mkdir docs assets logs

This command builds three directories docsassets, and logs in your present location without repeating the process.

3. Building Nested Directory Trees

mkdir -p dev/python/scripts

Even if dev or python directories don’t exist, the -p flag instructs mkdir to create each parent as needed, no errors thrown if any are already there.

4. Custom Permissions at Creation

mkdir -m 770 shared_folder

This line creates a folder with read, write, and execute permissions for the owner and group, while keeping everyone else out, a quick way to control access at the start.

5. Feedback for Each Directory (Verbose Mode)

mkdir -v assets/images

You’ll see a confirmation message for every directory built, which is helpful when running scripts or making multiple folders at once.

6. Avoiding Permission Errors

If you get a “Permission denied” message, prepend sudo to create a folder in system directories (e.g. /opt):

sudo mkdir /opt/newservice

7. Directory Paths: Absolute vs. Relative

Create a folder in a specific location by using a full path:

mkdir /var/backups/june

Or, nest a folder within your current working directory:

mkdir reports/weekly

Conclusion

The mkdir command is indispensable for structuring your digital workspace in Linux. By mastering its options like verbose feedback, permission settings, and multi-level folder structures. You’ll speed up workflow, keep projects orderly, and avoid common pitfalls. Always check for proper permissions before creating directories, and use the handy options to tailor your folder setup exactly to your needs.

Read More : History of linux

0xSnow

0xSnow is a cybersecurity researcher with a focus on both offensive and defensive security. Working with ethical hacking, threat detection, Linux tools, and adversary simulation, 0xSnow explores vulnerabilities, attack chains, and mitigation strategies. Passionate about OSINT, malware analysis, and red/blue team tactics, 0xSnow shares detailed research, technical walkthroughs, and security tool insights to support the infosec community.

Recent Posts

groupdel Command in Linux: Remove a Group and Audit Files

The groupdel command in Linux removes a group from the system. It deletes the group's entry from /etc/group and /etc/gshadow,…

12 hours ago

wc Command in Linux: Count Lines, Words, Characters, and Bytes

The wc command in Linux counts lines, words, characters, and bytes in files or standard input. It…

12 hours ago

top Command in Linux: Monitor Processes and Resource Usage

The top command in Linux provides a real-time view of running processes and system resource usage. From…

12 hours ago

usermod Command in Linux: Modify User Accounts and Groups

The usermod command in Linux modifies existing user account attributes. You can use it to manage group…

12 hours ago

sort Command in Linux: Sort Text, Numbers, Columns, and More

The sort command in Linux reads lines from files or standard input and writes them to standard…

2 days ago

wall Command in Linux: Broadcast Messages to Logged-In Users

The wall command in Linux sends a message to the terminals of all currently logged-in users. The…

2 days ago