automatically rename file to unique filename

automatically rename file to unique filename

Post by smath.. » Sat, 18 Dec 1999 04:00:00



Hi folks,

I am not a unix guy but have to get this thing working. I have a Sun
Box & want to automatically rename a file as soon as it is created in
the specified directory. The name has to be a unique filename
identified by creation date/time.

Thanks in advance for your help.

Sheetal

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

automatically rename file to unique filename

Post by m.. » Sat, 18 Dec 1999 04:00:00



> Hi folks,

> I am not a unix guy but have to get this thing working. I have a Sun
> Box & want to automatically rename a file as soon as it is created in
> the specified directory. The name has to be a unique filename
> identified by creation date/time.

I take it you don't have source code for the program that's creating
the files?

The obvious solution - getting a notification of a new file - isn't
available in Unix. You'd have to poll the directory periodically for
new files. The trick there would be to recognise a new file from the
ones you've already renamed.

Assuming that the names you want to give the new files are of the form
'yyyymmddhhmmss', and that you can guarantee that the program creating
the files won't ever give one a name like that, you could probably
work out a way to stat(2) all the files in the directory periodically,
and rename any that don't meet your needs based on the timestamp
returned by stat().

Look at the man page for stat(2) (ie, run the command 'man 2 stat').

 
 
 

automatically rename file to unique filename

Post by Brian Scanla » Sat, 25 Dec 1999 04:00:00



> I am not a unix guy but have to get this thing working.

Whether you're a Unix guy, NT gal, Mac dog or VMS frog, you've to read manuals
and learn howto do things yourself ;)

Quote:> I have a Sun
> Box & want to automatically rename a file as soon as it is created in
> the specified directory. The name has to be a unique filename
> identified by creation date/time.

I'd use this - You can get the PID of the process that's creating the file
from a shell by using "$$", and get the number of seconds since Jan. 1st 1970
using date '+s' (I think that's what it does...), so a command like

touch foobar.$$.`date '+%s'`

should create a unique filename, in the example which I just tried out on my
workstation, I got this file created.
foo.23097.946046140

Seems pretty unique to me  - Unless you happen to spawn off tens of thousands
of new processes in a second on your machine, I reckon you're safe enough.

Hope this helps :)

Brian.
--

Horizon Open Systems Ltd.                       http://www.hos.horizon.ie
East Point Business Park                        Tel:+353-1-805-5700
Dublin 3, Ireland                               Fax:+353-1-805-5601

 Sent via Deja.com http://www.deja.com/
 Before you buy.

 
 
 

1. renaming files from filename to filename-date

I am trying to come up with a one liner.  Doesn't really matter in which
shell I do it . . .

I am attempting to copy all of the files in one directory to their same
names but with a -MM_DD_YY appended.

for example, something like:

mv *.log *.`date '+%m_%d_%y'`

of course this doesn't work but if you have any suggestions I would love
to see them.  I know I've done this in the past but I just can't
remember how . . .

Thanks,
Diana

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Benchmarks for UNIX (solaris..) %^)

3. Creation of unique filename for temp file.

4. Problems running Postgres95 monitor

5. Rename files automatically

6. kde won't start up

7. how can I rename files with spaces in the filenames

8. ppp0 up ???

9. renaming files by removing a single character from original filename

10. a file of filenames compared to another file of filenames

11. How to get a unique filename?

12. ensuring unique FTP upload filenames

13. unique filenames in Makefile