This is a mix of shell, linux, and macOS commands. Comments are welcome with any corrections or suggestions.
PowerShell & Bash Comparison
See all aliases with
Get-Alias and to expedite your cli usage you could use a gist like this: Aliaser.ps1
Note that PowerShell eschews brevity for clarity, but you can alias anything you like to be nearly as succint as bash commands.
IMO readability/brevity trumps succintness. However for interactive terminal usage aliasing can be a great tool. Use VSCode to auto-expand aliases into fully qualified functions if you decide to turn your adhoc work into a script file.
pushd in a PowerShell session actually aliases to
The difference is in addition to the path string pushd manages, you get a .NET object back with
[System.Management.Automation.PathInfo] information including: Drive, Path, Provider, ProviderPath.
PowerShell Works With Native Tooling
I’ve included the similar PowerShell command to help those jumping between multiple shells.
Please note that unlike Python, PowerShell works as a terminal with native tools + scripting language.
You can use
pwsh in almost every case in Linux & macOS and use the same tools you prefer, while being able to execute PowerShell commands as well.
For example something like aws cli returning json could be automatically unmarshaled into an object instead of using
Another example is paths.
Prerequiresites for the PowerShell examples:
|Execute Line from History|
|Execute Last Command But With Sudo|
|Test file exists|
Common App Installs
|HomeBrew||Works on Linux and macOS now 👏.|
A Few More Ansible Commands
|Run ansible playbook against a specific tag|
This tool is great for cross-platform shell scripting as it runs all the commands in the
Taskfile.yml using a built in go shell library that supports bash syntax (and others).
Quickly get up and running using the directions here: Install Task
|Default Installation to local directory with debug logging enabled|
|Installation for user level access|
Installing Brew Packages
This eliminates any attempt to install if the package already exists. For quick adhoc installs, this is useful.
Only Proceed If First Condition Returns Nothing
On error do this:
On success do the next command:
Fetch A GitHub Release
This contains a few things, including curl, jq parsing, and movement commands.
This provides a shell script example of using those to get the latest release from GitHub, parse the json, then move this to target path. This release doesn’t wrap in a tar file; it’s just a binary.
This might fail due to anonymous API hits on GitHub api are rate limited aggressively.
Fetch a GitHub Release That Requires Extraction
This is more of a Linux focused shell script example for grabbing a release and extracting the tar file.
A common pattern is just
To make your script more portable, by respecting the users env preferences try:
Some good info on this from Shebang
If you do not specify an interpreter line, the default is usually the
For a system boot script, use
/usr/bin/env run a program such as a bash in a modified environment. It makes your bash script portable. The advantage of #!/usr/bin/env bash is that it will use whatever bash executable appears first in the running user’s
Setup your permissions for
I’ve had issues with macOS adding an
@ with ACL issues on the ssh key’s when downloaded.
To resolve this, just copy the contents of the ssh key to a new file and remove the original.
AWS CLI & Metadata
Retrieve Instance Region
Looks like the metadata service uses tokens now, so this requires an additional step.
List Matching Instances
You can use output with
--output text but for this example I used json and
List Standard Users