Deleting, Writing and Editing
Delete safely with -WhatIf first, write and add to files, edit a file in the terminal, and watch a file grow.
Updated
Deleting
- Deleting Safely: Remove-Item, -WhatIf and -Confirm (Novice): Remove-Item deletes files and folders with no Recycle Bin to catch them, so you rehearse a delete with -WhatIf, approve each item with -Confirm, and add -Recurse only for a folder you've looked inside.
Writing
- Writing to Files: Set-Content, Add-Content and > (Novice): Set-Content writes a file, replacing whatever it held, Add-Content adds lines to its end, and > and >> save a command's output into a file the same two ways, in UTF-8 text.
- Editing in the Terminal: edit (Novice): edit opens a text file in Microsoft Edit, an editor inside the terminal where the arrow keys and the mouse both work, Ctrl+S saves and Ctrl+Q quits, and notepad and code open the same file in a window.
Watching
- The Start and End of a File: -TotalCount, -Tail and -Wait (Apprentice): Get-Content -TotalCount shows only a file's first lines and -Tail only its last, and -Wait keeps a file open on screen so every line added to it appears as it's written, until Ctrl+C stops it.
Exercise: The Moving-Day List
- Exercise: The Moving-Day List (Apprentice): Clear the hallway of a new apartment with Remove-Item and -WhatIf, write and add to its lists with Set-Content, Add-Content, > and >>, fix a settings file with edit, and read the ends of two long files, while a Pester check tells you which jobs are done.