'touch' is not recognized as an internal or external command

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
4 min

banner

# 'touch' is not recognized as an internal or external command

The error "'touch' is not recognized as an internal or external command, operable program or batch file" occurs when we try to use the touch command on Windows.

To solve the error, run the npm install touch-cli -g command to be able to use the touch command.

touch is not recognized as internal or external command

touch is a Unix/Linux command, so it can't directly be used on Windows.

However, you can install the touch-cli npm package to be able to use the touch command on Windows.

If you don't have Node installed, you have 3 options:

  • scroll down to use an alternative command.
  • follow the instructions in the Installing Node.js subheading.
  • use the touch command in Git Bash.

Open your CMD shell and run the following command to install touch-cli.

cmd
npm install -g touch-cli

After you install the touch-cli package, you can use the touch command as follows.

cmd
# ๐Ÿ‘‡๏ธ Create a zero-sized new file touch my_file.txt # ๐Ÿ‘‡๏ธ Update the last modified and access timestamps of an existing file touch existing_file.txt

using touch on windows

Alternatively, if you simply need to create a file, you can use the type nul>file_name.txt command.
cmd
# ๐Ÿ‘‡๏ธ for CMD type nul>file_name.txt # ๐Ÿ‘‡๏ธ for PowerShell (raises error if file exists) New-Item file_name2.txt -type file

Make sure to replace file_name.txt with the name of the file you want to create.

windows touch alternative

You can also run the touch command directly in Git Bash. If you have git installed, type Git Bash in the Search field and start the application, otherwise, install git.

# Running the touch command in Git Bash

To download git and be able to use Git Bash:

  1. Open the git downloads page and download the installer for Windows.
  2. Start the installer.
  3. You will be prompted to select a destination location. You can leave the default option and click Next.

git select destination location

  1. You will be prompted to select components on the next screen. Leave the default options and click Next.

git select components

  1. Click Next on the screen that prompts you to "Select Start Menu Folder".

  2. On the next screen, you can choose the default editor for Git, e.g. Notepad, Notepad++ or any other editor you prefer.

choose git default editor

  1. On the "Adjust the name of the initial branch in new repositories screen", click Next.

adjust name of initial branch

  1. On the "Adjust your PATH environment" screen, make sure you have the default option of "Git from the command line and also from 3rd-party software" option selected and click "Next".

adjust your path environment

  1. For all the remaining screens, leave the default option selected and click Next.
  2. Lastly, click on the Install button to install git.

Once you have git installed, click on the Search field, type "Git Bash" and start the application.

search for git bash

Now you can use the touch command directly in Git Bash.

GitBash
# ๐Ÿ‘‡๏ธ Create a zero-sized new file touch my_file.txt # ๐Ÿ‘‡๏ธ Update the last modified and access timestamps of an existing file touch existing_file.txt

using touch command in git bash

If you need to open Git Bash in a specific folder:

  1. Open the folder in a new window.
  2. Right-click in Explorer.

open git bash in folder

  1. Click "Git Bash Here".

Now you can use the touch command to create a new file.

GitBash
# ๐Ÿ‘‡๏ธ Create a zero-sized new file touch my_file.txt # ๐Ÿ‘‡๏ธ Update the last modified and access timestamps of an existing file touch existing_file.txt

Alternatively, you can install Node.js to be able to use npm to install the touch-cli package.

# Installing Node.js to be able to use touch on Windows

To install Node:

  1. Open the nodejs.org page and download the Windows installer for the LTS (long-term supported) version.

download node lts version

  1. Start the installer and click Next on the Welcome screen.

node start installer

  1. Accept the End-User License Agreement and click Next.

node accept end user agreement

  1. Leave the default destination folder selected and click Next.

node select destination folder

  1. On the "Custom Setup" screen, click Next.

node custom setup

  1. You can optionally install tools for native modules, otherwise, click Next.

node tools for native modules

  1. On the next screen, click on the Install button.

node click install

  1. Lastly, click on the Finish button.

node click finish

  1. You can start a new CMD shell and use the npm --version command to make sure Node is installed.
cmd
npm --version node --version

get node npm version

Open your CMD shell and run the following command to install touch-cli.

cmd
npm install -g touch-cli

After you install the touch-cli package, you can use the touch command as follows.

cmd
# ๐Ÿ‘‡๏ธ Create a zero-sized new file touch my_file.txt # ๐Ÿ‘‡๏ธ Update the last modified and access timestamps of an existing file touch existing_file.txt

using touch on windows

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev