PSA: How to create a random password in the command line (something that also just learned to do today, so also a TIL entry):

```bash
randpass () { echo $(openssl rand -base64 "${1:-12}") }
```

The way this works is that you can type either `randpass`, and you will get a random password of 12 character (among those that are safe in the base64 representation; namely, lowercase and capital letters, decimal digits, plus `+` and `/`, and `= ` for padding).

Or, you can type `randpass 8` or `randpass 256`, for instance, to get a random password of the given characters long, to accommodate the needs from the service you need the password for.

On the Mac, you can do `randpass | pbcopy` and get it directly on your clipboard, so that you can paste it elsewhere, while keeping it hidden.

#PSA #PublicServiceAnnouncement #TIL #TodayILearned #CLI #CommandLineInterface #openssl #pbcopy #bash #zsh

How To Use Pbcopy And Pbpaste Commands On Linux - OSTechNix

Discover how to replicate macOS pbcopy and pbpaste commands functionality in Linux using Xclip and Xsel programs.

OSTechNix

I regularily use #pbcopy and #pbpaste shell commands on #MacOS. They are great to quickly process text. E.g. this formats JSON in clipboard and puts it back to clipboard:

$ pbpaste | jq | pbcopy

or this find the number of unique lines containing the word foo in file.txt:

$ grep foo file.txt | sort | uniq -c | pbcopy

PS: you can use `xmllint --format -` to format XML rather than #jq for JSON

macOS CLI Protip:

The 'pbcopy' command is *tremendously* useful. It sticks whatever is directed in via stdin into the Copy/Paste buffer!

`pbcopy < somescript.sh`

its twin 'pbpaste' comes in handy less often, but is good to keep around.

#mac #macOS #CLI #macOSCLI #pbcopy