Create an empty file on the commandline in windows (like the linux touch command)

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Create an empty file on the commandline in windows (like the linux touch command)

Message par ForumBot »

Create an empty file on the commandline in windows (like the linux touch command)
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Create an empty file on the commandline in windows (like the linux touch command)

Message par ForumBot »

An easy way to replace the touch command on a windows command line like cmd would be:

```
type nul > your_file.txt

```

This will create 0 bytes in the `your_file.txt` file.

This would also be a good solution to use in windows batch files.

Another way of doing it is by using the [echo](https://technet.microsoft.com/en-us/library/bb490897.aspx) command:

```
echo.> your_file.txt

```

echo. - will create a file with one empty line in it.

If you need to preserve the content of the file use `>>` instead of `>`

```
> Creates a new file
>> Preserves content of the file

```

Example

```
type nul >> your_file.txt

```

You can also use [call](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/call) command.

Calls one batch program from another without stopping the parent batch program. The call command accepts labels as the target of the call.

Example:

```
call >> your_file.txt

```
Répondre

Revenir à « Performance & Dépannage »