Command line GUID for Unix and Windows?
Asked Answered
M

6

25

Is there a command line tool for Unix and Windows that uses the same algorithm to create GUIDs for both platforms?

Maddie answered 20/2, 2009 at 15:2 Comment(1)
in windows you can do this with powershell like so: [guid]::newguid()Caffey
C
31

'e2fsprogs' project maintain uuidgen utility.

http://e2fsprogs.sourceforge.net/

It is already available on any Linux/BSD* distros.

For Windows I recommend install Cygwin, 'e2fsprogs' package available from there!

As report j4y this utility is available under MAC OS.

Just run:

  $ uuidgen -r  # random based UUID/GUID
  $ uuidgen -t  # time based UUID/GUID
Conall answered 15/7, 2010 at 20:54 Comment(2)
Cygwin package is "util-linux" Package Listing The command will also work without parameters in cygwin.Snobbish
uuidgen is now part of util-linux.Alcot
B
3

I don't know if there is a command line tool available, but you could simply write one in C# (it should run with Mono):

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(System.Guid.NewGuid().ToString());
    }
}

You can easily modify the program to change formatting of the GUID, copy it to the clipboard or whatever fits your need.

Brightwork answered 20/2, 2009 at 15:7 Comment(4)
Well I need to be sure they use the same algorithm to generate the GUID, and since Mono is not officially MS, I don't know if they use the same algorithm, do you have any specs about this?Maddie
Mono probably might use a different implementation but you could run the tool using Mono on both Windows and Unix/Linux. Just because I'm curious: Why do you need the same algorithm on both platforms? The GUID will still be unique because one field in the GUID specifies the algorithm used.Brightwork
The whole idea of a GUID is that it's globally unique if the algorithm and random number generator are up to par. I think you'd be safe with different algorithms generating GUIDs.Copal
Wedge got it right. The GUID includes a version marker (which specifies which algorithm is used). This ensures that no two GUIDs with different algorithm can ever be the same. And if the algorithm matches, then it's already tailored to ensure that no two GUIDs are the same.Pya
K
3

Something useful to know:

The byte order of Guid.ToByteArray() in C# and the SQL Server GUID type is:

        { 3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15 };

An Oracle GUID created using SYS_GUID() and stored as RAW[16] is ordered:

        { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

You may find this online GUID converter handy. I'm not sure if the source is available for your own use, but it shouldn't be too hard to figure it out.

Kirsten answered 20/2, 2009 at 20:27 Comment(2)
Shouldn't the string representation be the same, regardless of underlying byte order?Pya
Yes, but this is just a handy tip offered in case you ever have to deal with a GUID in byte order.Kirsten
C
1

In Windows XP, you can use the following in the command window.

uuidgen.exe
Culverin answered 12/10, 2009 at 13:21 Comment(3)
uuidgen isn't available out of the box in Windows; it's part of the Platform SDK / Windows SDK.Estrous
not in windows 10Wexler
After installing visualstudio2019buildtools with Chocolatey, I have ""C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64\uuidgen.exe". This creates a new random (uuidv4) on every invocation and writes it to stdout.Besotted
E
1

If you're on a system which already has python, you can simply run this on the command line:

python -c "import uuid; print(uuid.uuid4())"

(Python comes pre-installed on many Linux distributions, as well as on MacOS)

Executioner answered 22/4, 2021 at 10:39 Comment(0)
M
0

There are tons of online apps to do it.

If you are using PHP, you can use the uniqid function.

I found a pure Java program to do it at http://jug.safehaus.org/. That should work anywhere you can install Java.

Mendelevium answered 20/2, 2009 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.