Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

UNIX(Linux)
Beginner

  1. What is UNIX (Linux)? - Japanese Only
  2. What are Distributions? - Japanese Only
  3. About CentOS, macOS, and CUI - Japanese Only
  4. Installing CentOS with Virtualization Software and macOS CUI Environment - Japanese Only
  5. Login, root User, and Shutdown - Japanese Only
  6. Command Structure and Important Notes - Japanese Only
  7. File System and Navigating Directories (cd and pwd) - Japanese Only
  8. Key Directories and Listing Contents (ls) - Japanese Only
  9. Advanced Directory Navigation (cd) and Paths - Japanese Only
  10. Advanced ls Command (Part 1) and Dotfiles - Japanese Only
  11. Advanced ls Command (Part 2) - Japanese Only
  12. Tab Completion for Input - Japanese Only
  13. Creating Directories (mkdir) - Japanese Only
  14. Quick File Creation (touch) and About Files - Japanese Only
  15. Standard I/O, Redirection (> and >>), echo, and cat - Japanese Only
  1. Deleting Files and Directories (rm) - Japanese Only
  2. Copying Files and Directories (cp) - Japanese Only
  3. Moving and Renaming Files and Directories (mv) - Japanese Only
  4. What is the vi Editor? - Japanese Only
  5. Basic vi Usage (Part 1) - Japanese Only
  6. Basic vi Usage (Part 2) - Japanese Only
  7. Remote Operations via Terminal (SSH and Tera Term) - Japanese Only
  8. Installing Software (yum and Package Managers) - Japanese Only
  9. User Overview, Verification, Creation, and Switching (adduser and su) - Japanese Only
  10. User Passwords, Deletion, Modification, and sudo (passwd, userdel, usermod) - Japanese Only
  11. About Groups and the groups Command - Japanese Only
  12. Adding, Deleting, and Modifying Groups (groupadd, groupdel, groupmod) - Japanese Only
  13. About Permissions - Japanese Only
  14. Setting Permissions (chmod and chown) - Japanese Only
  1. Home
  2. UNIX(Linux)Beginner - Creating Directories (mkdir)

Creating Directories (mkdir) - Japanese Only

みなさまどうも。

続きましてディレクトリの作成方法についてみていきましょう。

ディレクトリを作成する場合には『mkdir』コマンドくんを使います。使い方はとっても簡単で「mkdir ディレクトリ名」って入力すればOKです。

ちょいと試してみましょう。まず今現在『/root』にいるとして「mkdir test」と叩いてみます。

[root@localhost ~]# mkdir test

もうこれだけでディレクトリが生成されています。『ls』コマンドで中身を確認してみると

[root@localhost ~]# ls
test

って感じですね。

ちなみに引数(ディレクトリ名のとこ)に複数の文字列を渡して複数のディレクトリを同時に生成することも出来たりするのでそれも紹介しておきます。こんな感じでございます。

[root@localhost ~]# mkdir test1 test2
[root@localhost ~]# ls
test  test1  test2

これも便利なので覚えておくと良いかもです。

そして注意点なのですが「ディレクトリの中に更にディレクトリを作りたい」となった場合はそれを同時に行うことはできません。

例えば『test3』というディレクトリの中に『test4』を作る場合で以下のように

[root@localhost ~]# mkdir test3/test4

とするとエラーになります。

じゃあどうするのかというと最初にディレクトリ『test3』を作ってから『test4』を作る感じになりますね。

[root@localhost ~]# mkdir test3
[root@localhost ~]# mkdir test3/test4
[root@localhost ~]# ls -R
.:
test  test1  test2  test3

./test:

./test1:

./test2:

./test3:
test4

./test3/test4:

ここ間違いやすいのでご注意です。

そしてもういっちょ注意点なのですがディレクトリを削除する為のコマンドである『rmdir』くんって子が居ます。この子を使うと以下のようにディレクトリを削除できるわけなのですが

[root@localhost ~]# ls -R
.:
test  test1  test2  test3

./test:

./test1:

./test2:

./test3:
test4

./test3/test4:
[root@localhost ~]# rmdir test
[root@localhost ~]# ls -R
.:
test1  test2  test3

./test1:

./test2:

./test3:
test4

./test3/test4:

この子は「空のディレクトリじゃないと削除できない」という制約があるのでいまいち使えない子だったりするんですよね。

上記の場合は空のディレクトリである『test』を削除しているので『rmdir』でもOKなのですが、空じゃないディレクトリである『test3』を削除しようとしてもエラーで実行できません。

[root@localhost ~]# rmdir test3/
rmdir: failed to remove `test3' : Directory not empty

よくUNIX関係の辞書とかネットで検索したりした際に『rmdir』が出てきてしまって紛らわしいのですがこの子は正直覚えなくてOKかなって感じです。

ディレクトリを削除するときはちょっと先の記事で紹介する『rm -R』くんを使うようにしましょう。

というわけでキリが良いので少し短いかもですがこの辺で一旦切りますね。次の記事ではファイルの簡易作成についてやっていきましょう。

では失礼致します。

This article was written by Sakurama.

Author's beloved small mammal

桜舞 春人 Sakurama Haruto

A Tokyo-based programmer who has been creating various content since the ISDN era, with a bit of concern about his hair. A true long sleeper who generally feels unwell without at least 10 hours of sleep. His dream is to live a life where he can sleep as much as he wants. Loves games, sports, and music. Please share some hair with him.

If you find any errors or copyright issues, please .