I'm using Codecademy to learn command-line. When I tried to use the command touch file.txt
, it says,
'touch' is not recognized as an internal or external command, operable program or batch file.
I searched on the forum and found out that I can use echo.>file.txt
, and it worked.
I would like to know why the touch
command doesn't work. Is this because I'm using Windows and not Mac? Can someone explain to me? Thanks!
This is the screenshot on my laptop......
The Touch command is not already pre-installed in Windows. Execute the “npm install touch-cli -g” command in the command prompt to install the touch command. The “type” and “copy” commands in Command Prompt and “Get-Item” in PowerShell are the windows equivalent of the touch command.
Windows does not natively include a touch command. It will iterate over it argument list, and for each element if it exists, update the file timestamp, else, create it.
The touch command's primary function is to modify a timestamp. Commonly, the utility is used for file creation, although this is not its primary function. The terminal program can change the modification and access time for any given file. The touch command creates a file only if the file doesn't already exist.
touch
is not a command in the Windows shell, it is in the shells of Unix-like operating systems (Mac, Linux, etc) which provide derivatives of the original sh
shell.
For Windows you can either use the workaround you found, or install a terminal emulator like Cygwin. In fact, Windows 10 is currently having a Linux environment being built in, meaning you could use it like Ubuntu, which will provide the right shell for touch
.
I've encountered this today as well, but on my case while trying Node.js. Yup, as they mentioned touch is for Unix. It seems most tutorials out there were created while using Macs. Anyway, I found another workaround, install touch via NPM...just make sure you are connected to the internet to download the package.
C:\npm install touch-cli -g
I was able to use touch after.
Another issue I've encountered while working with Windows 10 is I cannot change to a different directory. If you encounter it as well while following the tutorials, try this instead of "cd ".
cd /D <directory>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With