UNIX/Linux command basics Which command should you use to create a new directory (folder) from the shell?

Difficulty: Easy

Correct Answer: mkdir

Explanation:


Introduction / Context:
Creating directories is one of the first file-system skills in UNIX/Linux administration. The shell offers a dedicated utility to make new folders at any path, with optional creation of parent directories and permission control. Knowing the correct command, flags, and typical usage prevents errors and improves scripting reliability.


Given Data / Assumptions:

  • Operating in a UNIX/Linux command-line environment (bash, zsh, sh).
  • Destination path either exists or you have permission to create it.
  • No special characters in directory names beyond what the shell can handle with proper quoting.


Concept / Approach:
The standard tool is mkdir (make directory). It creates one or more directories supplied as arguments. Important flags include -p to create missing parent directories, and -m mode to set permissions at creation. The command is portable across distributions and POSIX-compliant shells.


Step-by-Step Solution:
To create a single directory in the current path: mkdir reports.To create nested parents: mkdir -p projects/2025/q1.To set permissions immediately: mkdir -m 750 teamshare.Verify using ls -ld directory_name to confirm ownership and mode.


Verification / Alternative check:
Run ls after creation to see the new entry. If -p is used and the directory exists, mkdir -p does nothing and returns success, which is useful in idempotent scripts.


Why Other Options Are Wrong:
crdir (Option A) and cr (Option D) are not standard UNIX commands.md (Option B) is a DOS/Windows alias, not portable on UNIX/Linux systems.None of the above (Option E) is wrong because mkdir is correct.


Common Pitfalls:

  • Forgetting quotes when names contain spaces.
  • Omitting -p when parents do not exist.
  • Creating directories in protected paths without sudo, causing Permission denied.


Final Answer:
mkdir

More Questions from Unix

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion