1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[ターミナル入門] ディレクトリ/ファイル操作

Last updated at Posted at 2020-03-22

はじめに

[用語]

  • ディレクトリ:フォルダのこと
  • ホームディレクトリ:Finderを立ち上げた時始めに表示されるフォルダ
  • カレントディレクトリ:今開いているフォルダの場所

[便利な小技]

  • 上矢印キー(↑)でコマンドのヒストリーをさかのぼれる
  • tabキーでディレクトリ・ファイル名の入力保管をしてくれる

ディレクトリパスの表示と移動

# カレントディレクトリを表示
pwd

# ホームディレクトリに移動
cd

# 1つ上の階層に戻る
cd ..

# 2つ上の階層に戻る
cd ../..

# 指定ディレクトリに移動する
cd 移動先ディレクトリのパス

ディレクトリ/ファイルを表示

# カレントディレクトリ内のディレクトリ/ファイルを表示
ls

# カレントディレクトリ内の、隠しファイルを含むディレクトリ/ファイルを表示
ls -a

ディレクトリ/ファイルの作成と名前変更

# 新規ディレクトリ作成
mkdir sample  // => sampleフォルダができる

# 新規ファイル作成
touch sample.html  // => sample.htmlファイルができる

既存ディレクトリ/ファイルの移動と複製

# ファイル名を変更
mv sample.html sample2.html  // => sample.htmlをsample2.htmlにファイル名を変更

# ファイルを別のディレクトリに移動
mv sample.html dev/  // => sample.htmlをdevフォルダに移動

# ファイルを複製
cp sample.html dev/  // => sample.htmlをdevフォルダ内で複製
cp sample.html sample2.html  // => sample.htmlをsample2.htmlという名前で複製

## ディレクトリを複製
cp -r dir1/ dir2  // => dir1をdir2という名前で複製

Finderを開く

## Finderを開く
open . // => カレントディレクトリでFinderを開く
open ~/  // => ホームディレクトリをFinderで開く
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?