Last updated: Apr 4, 2024
Reading timeยท4 min
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 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:
touch
command in Git Bash.Open your CMD shell and run the following command to install touch-cli
.
npm install -g touch-cli
After you install the touch-cli
package, you can use the touch
command as
follows.
# ๐๏ธ 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
type nul>file_name.txt
command.# ๐๏ธ 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.
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
.
touch
command in Git BashTo download git
and be able to use Git Bash:
Next
.Next
.Click Next
on the screen that prompts you to "Select Start Menu Folder".
On the next screen, you can choose the default editor for Git
, e.g.
Notepad
, Notepad++
or any other editor you prefer.
Next
.Next
.Install
button to install git
.Once you have git
installed, click on the Search field, type "Git Bash"
and start the application.
Now you can use the touch
command directly in Git Bash.
# ๐๏ธ 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
If you need to open Git Bash in a specific folder:
Now you can use the touch
command to create a new file.
# ๐๏ธ 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.
touch
on WindowsTo install Node:
Next
on the Welcome screen.Next
.Next
.Next
.Next
.Install
button.Finish
button.npm --version
command to make
sure Node is installed.npm --version node --version
Open your CMD shell and run the following command to install touch-cli
.
npm install -g touch-cli
After you install the touch-cli
package, you can use the touch
command as
follows.
# ๐๏ธ 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
You can learn more about the related topics by checking out the following tutorials: