links and unlinks files properly