0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSCodeのターミナルでTouchが使えない問題

Posted at

VSCodeターミナルで touchが使えない問題と解決法

はじめに

GitHubの勉強中、VS Code 内のターミナルで新しいファイルを作ろうと touch コマンドを使ったが、Windows 環境ではエラーが発生した。

エラー内容

touchコマンドでa.pyを作成しようとしたが、下記のエラーが発生した。

> touch a.py
touch : 用語 'touch' は、コマンドレット、関数、スクリプト ファイル、または操作可能なプログラムの名前として認識されません。名前が正しく記述されていることを
確認し、パスが含まれている場合はそのパスが正しいことを確認してから、再試行してください。
発生場所 行:1 文字:1
+ touch a.py
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (touch:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

エラーメッセージの原因

Windows の標準ターミナル(PowerShell や cmd.exe)では、touch コマンドは使えない。touch は Linux や macOS のシェルで使うコマンドで、Windows のネイティブコマンドセットには含まれていないからだ。

解決方法:Git Bash を使う

Git Bash は、Git をインストールしたときに提供されるシェルで、Linux のコマンド(touch も含めて)を Windows 上で使えるようにするツールだ。

使い方

  1. VS Code のターミナルを開く
  2. 画面下の矢印をクリックし、Git Bash を選ぶ

これで、Git Bash ターミナル内で touch コマンドを使えるようになる。新しいファイルも簡単に作れる。


まとめ

Git Bash を使うのが最も簡単で快適な方法だ。Linux のコマンドがそのまま使えるから、特に問題もなく作業が進む。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?