You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Linux/Unix系统中创建名称含"/"的目录?

Creating a Directory with a "/" in Its Name on SUSE Linux

Hey there! Let's cut to the chase: you can't create a directory with a real "/" character in its name on any Linux distro (including SUSE). The "/" is hardcoded as the system's path separator at the kernel level—any attempt to use it directly will just be interpreted as a new directory level, not part of the filename.

But if you need something that looks like a "/" in the directory name, here are the go-to workarounds specifically for this scenario:

1. Use a Full-Width Slash (U+FF0F)

This is the closest visual match to a regular slash, and the system doesn't treat it as a path separator. You can either:

  • Switch your keyboard to full-width mode and type it directly, or
  • Generate it via printf if you're working in a script or don't have full-width input enabled:
    # Direct input (full-width slash)
    mkdir "reports/2024-q3"
    # Generate via Unicode escape
    mkdir "$(printf 'project\uFF0Fv2')"
    

Pros: Looks identical to a regular slash at a glance.
Cons: Requires careful input—accidentally using a regular slash will create nested directories instead.

2. Use a Fraction Slash (U+2215)

This is a mathematical fraction slash that's visually similar but slightly more distinct. It's great if you want to avoid accidentally mixing it up with real path separators:

mkdir "$(printf 'src\u2215utils')"

Pros: Less likely to be confused with a real path separator than full-width slashes.
Cons: Still requires special input or printf to generate.

3. Fall Back to a Safe Alternative (Most Reliable)

If visual similarity isn't critical, using an underscore, hyphen, or another non-special character is the safest bet. It avoids all ambiguity and works with every tool/script out there:

mkdir "project_v2"
mkdir "src-utils"

Pros: 100% compatible with all Linux utilities and scripts—no surprises.
Cons: Doesn't look like a slash.

Important Note

Don't waste time trying to escape the regular "/" with backslashes (\) or quotes. Commands like mkdir "foo/bar" or mkdir foo\/bar will just create a bar directory inside a foo directory—they won't create a single directory named foo/bar. The kernel will always interpret "/" as a path separator, no matter how you escape it in the shell.

内容的提问来源于stack exchange,提问作者Moenik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 03:43:12