Python> library> os> link related> os.link () / os.readlink () / os.symlink () / os.unlink ()

Operating environment


Xeon E5-2620 v4 (8 cores) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 and its-devel
mpich.x86_64 3.1-5.el6 and its-devel
gcc version 4.4.7 (And gfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.Use 1.
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv

https://docs.python.org/3/library/os.html

It turns out that there are many OS-related functions in the os library. I've only looked at the ones that are related to what I'm working on.

I learned that you can read symbolic links with os.readlink (). So why not include the other functions of link?

http://qiita.com/7of9/items/132224132da34ca51d5f List the functions using test_python_170325b.py in.

$ python test_python_170325b.py  | grep function | grep "link'"
('link', <built-in function link>)
('readlink', <built-in function readlink>)
('symlink', <built-in function symlink>)
('unlink', <built-in function unlink>)

The above four are likely to be related.

os.link()

https://docs.python.org/3/library/os.html

os.link(src, dst, *, src_dir_fd=None, dst_dir_fd=None, follow_symlinks=True) Create a hard link pointing to src named dst.

os.readlink()

https://docs.python.org/3/library/os.html

os.readlink(path, *, dir_fd=None) Return a string representing the path to which the symbolic link points.

os.symlink()

https://docs.python.org/3/library/os.html

os.symlink(src, dst, target_is_directory=False, *, dir_fd=None)¶ Create a symbolic link pointing to src named dst.

os.unlink()

https://docs.python.org/3/library/os.html

os.unlink(path, *, dir_fd=None)¶ Remove (delete) the file path.

Difference between hard link and symbolic link

The following explanation was easy for me to understand.

http://cmd.misty.ne.jp/environment/03.html http://askubuntu.com/questions/108771/what-is-the-difference-between-a-hard-link-and-a-symbolic-link

So far, I'm only using symbolic links.

Supplement

SEE ALSO displayed by man ln etc. displays link (2) and symlink (2).

I don't know if Python's os library was named after these command names.

Recommended Posts

Python> library> os> link related> os.link () / os.readlink () / os.symlink () / os.unlink ()
Python os related files, subdirectory operations