Copy command line output to the clipboard on macOS, Windows, and Linux

NOTE: Updated for PowerShell 7, with Set-Clipboard available to supported platforms (Linux still requires xclip). You’ve just figured out the exact piece of information you need from a command line call. Now, how do you get it out of your terminal and take it somewhere else, like an email, chat, or document? Fortunately, there are already programs out there to make this easy. You can send the output from any command to one of these applications, and the output will be available in your clipboard. From there, you can paste it anywhere you please. In the case of Windows and macOS, there are programs to do this that come with the OS. On Linux, you can install a tool to have the same functionality. Windows Whether you are in Command Prompt or PowerShell (old-school or Core), you can use the Windows clip application to get output to the clipboard. Should it matter to you, clip will append an extra line break to whatever you feed it. command {some command} | clip For example, to dump your file listing to the clipboard, you would run dir | clip or Get-ChildItem . | clip, with dir working in both cmd and all… Continue reading

Determine SHA hash of file on Windows, Linux, and macOS

While it doesn’t guarantee a download hasn’t been compromised, sometimes you feel better knowing the file you downloaded matches the expected SHA hash. Full disclosure here: while I haven’t been paid or provided anything for this blog post, I am only creating this post for me. If it helps you, great! I just keep looking this up every time I need it. Instead of wading through a bunch of Stack Overflow answers to find the exact magic command I need, I’m hoping I’ll start finding my own blog post in my search results. SHA-256 hash commands Here’s what I use most days. There are bound to be other ways to do this, and on more operating systems or command line shells. As well, there may be ways that are better suited for certain tasks like scripting or other automation steps. For the occasional one-off hash needs, though, they get the job done. macOS shasum –algorithm 256 ~/Downloads/ Windows (cmd.exe) CertUtil -hashfile ~/Downloads/ SHA256 Windows (PowerShell) Confirmed in v6.1.3 [Core], but it probably works in several earlier versions. Get-FileHash -Path ~/Downloads/ -Algorithm SHA256 Linux I’ve only confirmed this on a few flavors of Ubuntu and Debian/Raspbian. sha256sum ~/Downloads/ Background If you… Continue reading