The task is to replace a file's (actually of all the files in a directory) name (but leave extension intact) with a random UUID/GUID. Any ideas on how to do this?
Tell me more
×
Unix & Linux Stack Exchange is a question and answer site for
users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
|
Similar to bahamat answer, but generates actual UUIDs. UUIDs have some reserved bits that are used to determine the version and variant used. There are currently 5 types of UUIDs defined, random UUIDs, as you asked, are version 4. You will note that version 4 UUIDs have this format: 442b7f35-f33f-4b8d-9a07-db8ec207129e
| '-- variant (bits 10__ -> [89AB])
'------- version (bits 0100 -> 4)
Also, this version doesn't cause damage in case the UUID generation fails.
Using /proc/sys/kernel/random/uuid:
|
||||
|
|
|
Something like this:
Using |
|||||||||
|
|
Short Perl script below - the use of cat to get the uuid isn't the cleanest/fastest way to code it, but it keeps the command short:
The above uses a file in /proc on linux as a source of uuids:
|
|||||||
|
