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: 
**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
From [docs](https://docs.python.org/3/library/os.html):

`os.replace()`

> 
> Rename the file or directory src to dst. If dst is a directory, OSError will be raised. If dst exists and is a file, it will be replaced silently if the user has permission. The operation may fail if src and dst are on different filesystems. If successful, the renaming will be an atomic operation (this is a POSIX requirement).
> 
> 
> 

`os.rename()`

> 
> Rename the file or directory src to dst. If dst exists, the operation will fail with an OSError subclass in a number of cases:
> On Windows, if dst exists a FileExistsError is always raised.
> On Unix, if src is a file and dst is a directory or vice-versa, an IsADirectoryError or a NotADirectoryError will be raised respectively. If both are directories and dst is empty, dst will be silently replaced. If dst is a non-empty directory, an OSError is raised. If both are files, dst it will be replaced silently if the user has permission. The operation may fail on some Unix flavors if src and dst are on different filesystems. If successful, the renaming will be an atomic operation (this is a POSIX requirement).
> This function can support specifying src\_dir\_fd and/or dst\_dir\_fd to supply paths relative to directory descriptors.
> 
> 
>