1

I am trying to create a global .gitignore file with this command:

touch ~/.gitignore

but in my terminal (Cmder) gives this message: "touch: cannot touch '~/.gitignore': No such file or directory"

I have changed to windows terminal default (Command Prompt) and it says: "'touch' is not recognized as an internal or external command, operable program or batch file."

What I am doing wrong or what can I do to solve this?

eis
  • 51,991
  • 13
  • 150
  • 199
Raquel Santos
  • 110
  • 18
  • If you work on windows there is no "touch" command. Check this question for alternatives https://stackoverflow.com/questions/30011267/windows-equivalent-of-touch-i-e-the-node-js-way-to-create-an-index-html – Daniel Camarda Jan 16 '21 at 12:17
  • @DanielCamarda `cmder` has the touch command though – eis Jan 16 '21 at 12:25
  • I have touch command in Cmder. The problem is not touch but this : ~/.gitignore – Raquel Santos Jan 16 '21 at 12:37
  • voiting to close in favor of question posted by Daniel, which contains answer in more detail. – eis Jan 16 '21 at 12:40
  • As @eis pointed out the problem may be in the path part of the command. If Cmder supports "touch" try "touch C:\something.txt" and check if it works. – Daniel Camarda Jan 16 '21 at 12:41
  • Yes the problem is not in command touch , it is in the ~/.gitignore. Because with Cmder I create my files with touch command without any problem at all. So my question is not the same of the links Daniel. – Raquel Santos Jan 16 '21 at 12:44
  • 1
    @RaquelSantos have you tried `touch "%USERPROFILE%\.gitignore"` – eis Jan 16 '21 at 12:45
  • @eis I think this is the answer . I wrote that and found a text file in my user profile .Is that it? – Raquel Santos Jan 16 '21 at 12:49
  • 1
    yes, that is what it's meant to do. added to my answer. – eis Jan 16 '21 at 12:50

2 Answers2

1

You are using linux syntax. Now, even though touch is not understood by cmd prompt, it is a command understood by cmder but expression ~/.gitignore is still linux way of saying things.

What you can do on cmd prompt, I guess also would work on cmder (edit: doesn't seem to work for cmder):

copy con "%USERPROFILE%\.gitignore"
[press F6 and enter after that]

For cmder, this could work:

touch "%USERPROFILE%\.gitignore"
eis
  • 51,991
  • 13
  • 150
  • 199
  • copy con "%USERPROFILE%\.gitgnore" [press F6 and enter after that] I didnt understood. You are saying that I write in cmder "%USERPROFILE%\.gitignore" without touch at the beggining? And then press F6 and enter? – Raquel Santos Jan 16 '21 at 12:34
  • @RaquelSantos first line is what you write to cmd prompt, then press enter, then you need to press F6 and again enter – eis Jan 16 '21 at 12:35
  • You are saying that I write in cmder "%USERPROFILE%\.gitignore" without touch at the beggining? And then press F6 and enter? – Raquel Santos Jan 16 '21 at 12:36
  • yes, that is what I'm saying. it is cmd prompt way of doing things, and I think it would also work on cmder. – eis Jan 16 '21 at 12:38
  • ok, then cmder doesn't work this way. Recommend using cmd prompt. – eis Jan 16 '21 at 12:41
0

This should help for windows terminal:

echo $null >> pot.txt

touch is linux command not windows command.

Below question should help a lot more : https://superuser.com/questions/502374/equivalent-of-linux-touch-to-create-an-empty-file-with-powershell

  • $null is not windows either, I wonder what you intended that to contain? – eis Jan 16 '21 at 12:24
  • echo is not windows either. but cmder emulator has those commands . I use touch to create files. If I create a normal file it works., What doesnt work is writting this after touch command ~/.gitignore – Raquel Santos Jan 16 '21 at 12:30
  • @RaquelSantos echo certainly is windows stuff (also) – eis Jan 16 '21 at 12:34