What is the powershell equivalent to linux command "touch" ?

Hi People,

Can anyone please suggest me what is the correct powershell command to "touch" a file like in Linux environment ?

Copy-Item .\somefile.xml \\.\nul\

Open in new window


does that code performs the same thing ?
LVL 9
Senior IT System EngineerIT ProfessionalAsked:
Who is Participating?
 
footechConnect With a Mentor Commented:
You're right, I forgot about that functionality of touch.  So I suppose that the answer depends on what functionality of the utility needs to duplicated.  Otherwise, a function could be created to handle multiple functions depending on conditions.
0
 
Seth SimmonsConnect With a Mentor Sr. Systems AdministratorCommented:
use New-Item

http://technet.microsoft.com/en-us/library/ee176914.aspx

PS C:\Users\seth> New-Item foo.txt -type file


    Directory: C:\Users\seth


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        10/22/2013   7:31 PM          0 foo.txt

Open in new window

0
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
ah ok, so what does the Copy-Item .\somefile.xml \\.\nul\ does then ?
0
 
footechConnect With a Mentor Commented:
I don't see how New-Item would work, it would just create a new file.
I also don't see how the Copy-Item command would work (and in testing it doesn't).
Since the touch command just updates the Last Modified timestamp on a file, here's an equivalent.
(Get-Item somefile.txt).LastWriteTime = Get-Date

Open in new window

0
 
Seth SimmonsConnect With a Mentor Sr. Systems AdministratorCommented:
if you go on a linux machine and touch foo
it will create a file called foo; same as New-Item
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.