LoginSignup
1
1

More than 5 years have passed since last update.

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

Last updated at Posted at 2017-03-27
動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 とその-devel
mpich.x86_64 3.1-5.el6とその-devel
gcc version 4.4.7 (とgfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.1を使用。
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv

osライブラリにはOS関連のfunctionが多数あることはわかった。
この中で、自分が今作業しているものと関連するものだけ見てみた。

os.readlink()にてsymbolic linkを読めるということは教えていただいた。
では、linkの他の関数を含めてどうか。

http://qiita.com/7of9/items/132224132da34ca51d5f
test_python_170325b.pyを使って関数をリスト化する。

$ 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>)

上記の4つが関連しそうだ。

os.link()

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()

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

os.symlink()

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

os.unlink()

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

hard linkとsymbolic linkの違い

以下の説明が自分には分かりやすかった。

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

今のところ、ほとんどsymbolic linkしか使っていない。

補足

man lnなどで表示されるSEE ALSOにはlink(2)symlink(2)が表示される。

Pythonのos libraryがこれらコマンド名にのっとって付けられたかは知らない。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1