jlevy / the-art-of-command-line

Master the command line, in one page
152.73k stars 14.52k forks source link

A few more one-liners #509

Open jlevy opened 7 years ago

jlevy commented 7 years ago

We should have a few more judiciously chosen examples in https://github.com/jlevy/the-art-of-command-line#one-liners

The examples should be nontrivial (to make you think or look stuff up), useful (not just entertainment), illustrative/interesting (will make sense to a lot of people), not overtly encouraging bad behavior (obfuscations or error-prone habits), and each one a little different from the others.

jlevy commented 7 years ago

Suggestions or ideas welcome — comment here! :)

geekmuse commented 7 years ago

I suppose this falls outside of the strict definition of "one-liner", but it works rather nicely for displaying the number of AZs for a given region (also depends on jq being installed):

echo -e "$(tput bold)Region          | # AZs$(tput sgr0)";for region in $(aws ec2 describe-regions | jq -r '.Regions[].RegionName'); do
    num_azs=$(aws ec2 describe-availability-zones --region ${region} | jq -r '.AvailabilityZones | length')
    printf '%-15s | %5s\n' ${region} ${num_azs}
done
geekmuse commented 7 years ago

Good quick one for grabbing the state of creation of an AMI (usually use in some kind of while loop):

aws ec2 describe-images --owners "self" --region ${region} | jq -cr ".Images[] | select(.ImageId | contains(\"${ami_id}\")) | .State"
geekmuse commented 7 years ago

Either of those ^ work nicely as a function in your .bashrc/.zshrc - happy to provide the extra wrapping code if desired.

jlevy commented 7 years ago

Thanks @geekmuse ! Want to get some more examples and we'll somehow get them in.

erictleung commented 6 years ago

Although the use case for these one-liners are for bioinformatics, here's a good list to borrow from https://github.com/stephenturner/oneliners