One-Liners

From CDZwiki
Jump to: navigation, search

A well maintained library of one-liners can accomplish nearly anything. Below are some of my favorite one-liners of code organized by language.

Microsoft PowerShell

Microsoft's PowerShell is a very underrated piece of technology that allows for full control of a modern Windows system strictly through command line. While not a programming language in itself, PowerShell is privileged & capable enough to stand in for many other languages on a Windows system.

File Management

Checksum Whip up a quick SHA1 (or other algorithm) checksum of a directory's contents where $t is your target directory.

Get-ChildItem $t -recurse | Select-Object -expandproperty FullName | ForEach-Object {Get-FileHash $_ -Algorithm SHA1} | Format-List

VHD Mount Mount a VHD file for use in a script where $vhd is your VHD target.

$b = (Get-Volume).DriveLetter; $r = Mount-DiskImage -Imagepath $vhd -passthru; $p = (compare $b (Get-Volume).DriveLetter -PassThru)+":\"

Web Crawl

Weather Get weather for your area, properly formatted for PowerShell (intended for fixed width) where "milton,vermont" is your town,state.

$wtr = Invoke-WebRequest -uri "wttr.in/milton,vermont" -usebasicparsing; $otpt = ((($wtr.RawContent -Split "\lpre\g")[-1]) -Split "\l/pre\g")[0].Split("┌")[0] -Replace "`\lspan` class`=`"(\w|\d)*`"`\g","" -Replace "\\l\/span\\g","" -Replace "`&quot`;`&quot`;","`"`"" -Replace "`n","`r`n"; $otpt = $otpt -Split "`r`n"

Microsoft Batch

Batch is a trusty utility useful for a variety of simple tasks on a Windows machine. Though a bit dated, .bat files are still heavily relied on in the Microsoft world.

Bash Script

The Go-To shell for Linux. Anything you've ever wanted to accomplish in Linux can be done with Bash Script; entire appliances have been written with just Bash!

PHP

PHP is just as underrated as PowerShell, or at least as shunned! For whatever reason, I've encountered a lot of grief over PHP, however this language is perfectly capable and runs the majority of the web these days. People only dislike PHP because they don't understand it.