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.
mkdir [options] directory_nameYou 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.
| Option | Description |
|---|---|
| -p | Create parent directories as needed (no errors if they already exist) |
| -m | Set permissions for new directories at creation (e.g., 755 for rwxr-xr-x) |
| -v | Display a message for every directory created (verbose) |
| –version | Output version and license details |
| –help | Show help and available options |
| -Z | Set SELinux security context for new directories (advanced/security environments) |
mkdir workspaceCreates a folder named workspace in your current directory.
mkdir docs assets logsThis command builds three directories docs, assets, and logs in your present location without repeating the process.
mkdir -p dev/python/scriptsEven 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.
mkdir -m 770 shared_folderThis 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.
mkdir -v assets/imagesYou’ll see a confirmation message for every directory built, which is helpful when running scripts or making multiple folders at once.
If you get a “Permission denied” message, prepend sudo to create a folder in system directories (e.g. /opt):
sudo mkdir /opt/newserviceCreate a folder in a specific location by using a full path:
mkdir /var/backups/juneOr, nest a folder within your current working directory:
mkdir reports/weeklyThe 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
A newly disclosed Android vulnerability is making noise for a good reason. Researchers showed that…
In MySQL Server 5.5 and earlier versions, the MyISAM was the default storage engine. So,…
A newly disclosed vulnerability in Microsoft Authenticator could expose one time sign in codes or…
Modrinth is a modern platform that’s rapidly changing the landscape of Minecraft modding, providing an…
A new, highly sophisticated malware campaign named BlackSanta has emerged, primarily targeting HR and recruitment…
Perplexity has unveiled an exciting new feature, Personal Computer, which allows AI agents to seamlessly…