I have a program that regularly outputs files to a directory, let's say /a/b
. I am utterly unable to change where these files are outputted. But for me to use them, I must first move them to, let's say, /c/d
, an already existing directory. I'm growing tired of regularly moving over the file contents, so is there some way to redirect everything written in that directory to another? I've already tried ln -s
but with my limited knowledge of the linking command I couldn't accomplish anything. Changing any code of the program is not possible. Thanks for the help.
2 Answers
short of being able to delete /a/b directory, your ln -s
command will not give you anything.
but if you can find a few seconds that nothing is writing to this /a/b
directory, you can do this :
cd /a
rm -r b # make sure you have a backup of the contents of this directory
ln -s /c/d b
now any application who will write into /a/b
, will be directed to write these files into /c/d
, provided they have write rights.
-
Okay, that seems like it would work, but one more question -
/c/d
is in a different partition. I need the data to write to this partition (in order to save space on the other), doesln -s
perform this function? Commented Mar 10, 2016 at 1:41 -
the
-s
in the command means symbolic link and symbolic links do not have to be in the same partition. That limitation is for the hard links which has to be in the same filesystem Commented Mar 10, 2016 at 1:47
Here:
while :; do cp /a/b/* /c/d/; sleep 60; done
It copies the entire content of /a/b/ to /c/d/ every 60 seconds.
It does have a drawback: If the files are big (more than a few GB?) then copying might take a while. If this is a problem, comment and I'll implement something optimised for big files (with tail -f) which will also redirect the content in real time