?
Solved

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

Posted on 2013-10-22
5
Medium Priority
?
3,923 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 35

Assisted Solution

by:Seth Simmons
Seth Simmons earned 1000 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 8

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 1000 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 1000 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

771 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