Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Overwrite files in place via perl script UNIX
This is a small hint, but it comes in handy if you edit iTunes files outside of iTunes. iTunes tracks files by inode (as does the Finder), so renaming a file and putting another in its place won't work.

This Perl script overwrites a file in place, preserving the inode. You can edit a copy of the file using any tool you wish, and then use this script to replace the original. iTunes will then use the new file. It won't notice changed tags immediately, but if you try to edit any of the track information, it will update with the correct information before letting you edit.

[robg adds: I haven't tested this one. Make sure you make the script executable with chmod 755 script_name before you try to use it.]
    •    
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[6,034 views]  

Overwrite files in place via perl script | 5 comments | Create New Account
Click here to return to the 'Overwrite files in place via perl script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Overwrite files in place via perl script
Authored by: kmue on Dec 15, '04 09:31:21AM

Why not 'cp src dst; rm src'?
This will preserve the inode of dst as well.



[ Reply to This | # ]
Overwrite files in place via perl script
Authored by: lenbudney on Dec 15, '04 09:54:11AM

I didn't know that cp preserved the destination inode. It's not in the man page; a web search turns up only a few hits that mention this tidbit. Thanks much for pointing it out!



[ Reply to This | # ]
Overwrite files in place via perl script
Authored by: CarlRJ on Dec 15, '04 02:18:33PM

It's not like cp does some special magic to preserve the destination inode, rather it's inherent in the way Unix works: cp simply opens the source file for reading, opens the (existing) destination file for writing, and copies bytes from one to the other. The only way to end up with a different inode for the destination file would be for cp to open/write an entirely new file, and then move the new file on top of the old file (but that's not what cp does).



[ Reply to This | # ]
Listing inodes
Authored by: thrig on Dec 15, '04 11:28:15AM

For those not versed in the unix traditions, ls -i and find . -ls will print the inode of matched files, which can be used when debugging whether a particular tool changes the number.



[ Reply to This | # ]
Overwrite files in place via perl script
Authored by: unforeseen:X11 on Dec 15, '04 05:56:23PM
If the Original File cannot be found (via Inode), iTunes will look for Files at the last known location with the same filename. So, you could delete the Original File (Empty the Trash!) and put another File with the Same Filename into that directory and iTunes will get the new one (but will immediadetly rename a mp3 if the Song-Name specified in the ID3-tag is different to the filename).

I'm glad iTunes does that since I had to recover my whole Music-Library back from the iPod. Recreating the Filesystem iTunes had before saved me re-assigning some 2000 Songs. It didn't work with every song, but with the most. ;)

[ Reply to This | # ]