0

I've got a directory which contains hundreds of thousands of files. A file typically looks like this : CED375_description_01.jpg. I need to move this file to another directory, but the file needs to be moved into the structure /ced/ced375/ced375_description_01.jpg.

What options do I have to achieve this?

Rex
  • 7,895
  • 3
  • 29
  • 45
sbrattla
  • 1,578
  • 4
  • 28
  • 52

1 Answers1

3

I am not aware of an application that will do this for you. Your most likely solution is to write a script yourself, it shouldn't really be that difficult.


It appears that the source directory is in fact an NFS mount (we don't know what the destination directory is). This means that inotify can't be used.

The internet suggests that FAM may be of use in this scenario.

user9517
  • 115,471
  • 20
  • 215
  • 297
  • The primary challenge is that the number of files in the source directory will reach 1 million soon, and traversing all files (with a simple script) to compare the source and target directory each and every time seems like a less than optimal approach. – sbrattla Feb 09 '15 at 11:44
  • Actually, the less than optimal approach was to put all the files in a single directory to start with. There are though utilities based upon incron that can monitor a directory and run commands when files are created/changed etc. – user9517 Feb 09 '15 at 11:55
  • Yes it is. If all files are in a single directory Linux offers for instance [`inotify`](https://github.com/rvoicilas/inotify-tools/wiki) to watch that directory for you, but changing the application that generates the filenames so a timestamp is included would already be a much better solution. – HBruijn Feb 09 '15 at 11:58
  • Yes, I meant `inotify` not `incron`. – user9517 Feb 09 '15 at 12:11
  • The directory is an NFS share, and I believe I can't really use inotify for NFS shares. – sbrattla Feb 09 '15 at 13:31
  • 1
    That kind of information should have been provided in your question rather thay as an aside i a comment. That makes it very much harder. The internet suggests [FAM](http://oss.sgi.com/projects/fam/index.html) – user9517 Feb 09 '15 at 13:55