Solved

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

Posted on 2013-10-22
5
2,808 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 34

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 39

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 34

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 39

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Last week, our Skyport webinar on “How to secure your Active Directory” (https://www.experts-exchange.com/videos/5810/Webinar-Is-Your-Active-Directory-as-Secure-as-You-Think.html?cid=Gene_Skyport) provided 218 attendees with a step-by-step guide for…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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