Question: I want to move a file form one directory to another in linux with python. I wish to achieve a behavior similar to bash `mv` command.

What is the difference in practice between the two commands

```
os.replace()
os.rename()

```

Is it simply that `os.rename()` will raise an error if file exists in destination while `os.replace()` will overwrite it?

Also if another secondary difference that I see it that the `os.replace()` needs a file as a destination not just the directory.

I can find a direct answer anywhere.

Answer: 
On POSIX systems, the [rename](https://man7.org/linux/man-pages/man2/rename.2.html) system call will silently replace the destination file if the user has sufficient permissions. The same is not true on Windows.

`os.replace` and `os.rename` are the same function on POSIX systems, but on Windows `os.replace` will call `MoveFileExW` with the `MOVEFILE_REPLACE_EXISTING` flag set to give the same effect as on POSIX systems.

If you want consistent cross-platform behaviour you should consider using `os.replace` throughout.
**os.rename()**

`os.rename()` method in Python is used to rename a file or directory.
This method renames a source file/ directory to specified destination file/directory.

**os.replace()**

`os.replace()` method in Python is also used to rename the file or directory.

but:

* If destination is a directory, `OSError` will be raised.
* If the destination exists and is a file, it will be replaced without error
if the action performing user has permission.
* This method may fail if the source and destination are on different filesystems