Operating System - HP-UX
1838246 Members
4138 Online
110125 Solutions
New Discussion

create a new file with unique filename ?

 
SOLVED
Go to solution
MARREEL Chris_1
Regular Advisor

create a new file with unique filename ?

I have once read a script where there was a command used to create a temporary file with a 'unique' filename in regards to the existing filenames in that directory.

I can't remember the command anymore.
Can anybode help ?

Thanks,
Chris MARREEL
3 REPLIES 3
Frederic Sevestre
Honored Contributor
Solution

Re: create a new file with unique filename ?

Hi,

You can use mktemp (with the option -p to force a prefix)

Fr??d??ric
Crime doesn't pay...does that mean that my job is a crime ?
Steve Steel
Honored Contributor

Re: create a new file with unique filename ?

Hi

Do not know the command but $RANDOM is always unique


filename=/tmp/$RANDOM$(date '+%d%m%y%H%M%S')

Will definately give a unique name


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
MARREEL Chris_1
Regular Advisor

Re: create a new file with unique filename ?

mktemp is indeed what I'm looking for.

Thanks,
Chris MARREEL