diff --git a/README.md b/README.md index b493879..20b2477 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1279 TILs and counting..._ +_1280 TILs and counting..._ --- @@ -1222,6 +1222,7 @@ _1279 TILs and counting..._ - [Curl With Cookies](unix/curl-with-cookies.md) - [Curling For Headers](unix/curling-for-headers.md) - [Curling With Basic Auth Credentials](unix/curling-with-basic-auth-credentials.md) +- [Different Ways To Generate A v4 UUID](unix/different-ways-to-generate-a-v4-uuid.md) - [Display All The Terminal Colors](unix/display-all-the-terminal-colors.md) - [Display Free Disk Space](unix/display-free-disk-space.md) - [Display The Contents Of A Directory As A Tree](unix/display-the-contents-of-a-directory-as-a-tree.md) diff --git a/unix/different-ways-to-generate-a-v4-uuid.md b/unix/different-ways-to-generate-a-v4-uuid.md new file mode 100644 index 0000000..914a06b --- /dev/null +++ b/unix/different-ways-to-generate-a-v4-uuid.md @@ -0,0 +1,27 @@ +# Different Ways To Generate A v4 UUID + +There have been times where I have needed a random UUID. Usually if I am +mocking some data or testing something out that needs a value in the shape of a +UUID. Here are a couple different ways to do this in the terminal, as +one-liners. + +With `ruby` and the `SecureRandom` class: + +```bash +$ ruby -e "require 'securerandom'; puts SecureRandom.uuid" +29e52b97-b43d-4025-a43d-70053b1d1a63 +``` + +With `psql` and the `gen_random_uuid()` function: + +```bash +$ psql -Xqtc 'select gen_random_uuid()' postgres | xargs +5a925ebd-c85f-4d94-a81e-e229c4cbe99f +``` + +With the `uuidgen` function that ships with Unix/Linux OSs: + +```bash +$ uuidgen +B11555D8-A256-4EC8-A0B0-9259FF88C3FC +```