Solved

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

Posted on 2013-10-22
5
3,185 Views
Last Modified: 2013-10-27
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 ?
0
Comment
  • 2
  • 2
5 Comments
 
LVL 35

Assisted Solution

by:Seth Simmons
Seth Simmons earned 250 total points
ID: 39592824
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
 
LVL 7

Author Comment

by:Senior IT System Engineer
ID: 39593114
ah ok, so what does the Copy-Item .\somefile.xml \\.\nul\ does then ?
0
 
LVL 40

Assisted Solution

by:footech
footech earned 250 total points
ID: 39593306
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
 
LVL 35

Assisted Solution

by:Seth Simmons
Seth Simmons earned 250 total points
ID: 39594569
if you go on a linux machine and touch foo
it will create a file called foo; same as New-Item
0
 
LVL 40

Accepted Solution

by:
footech earned 250 total points
ID: 39594664
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

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question