void (@NotNull Path dir) { if (SystemInfo.isUnix) { File empty = getEmptyTempDir(); if (empty.mkdir()) { try { // https://unix.stackexchange.com/a/79656/47504 List<String> command = new ArrayList<>(); command.add("rsync"); command.add("-a"); command.add("--delete"); command.add(empty.getPath() + "/"); command.add(dir + "/"); ProcessBuilder builder = new ProcessBuilder(command); Process process = builder.start(); process.waitFor(); int exitCode = process.exitValue(); LOG.info("rsync exited with " + exitCode); } catch (IOException | InterruptedException e) { LOG.warn("rsync failed: " + e.getMessage()); } finally { FileUtil.delete(empty); } } } FileUtil.delete(dir.toFile()); }