Я знаю о двух графических различных программах: Комбинация и KDiff3. Я не использовал KDiff3, но Комбинация работает хорошо на меня.
кажется, что оба находятся в стандартных хранилищах пакетов для openSUSE 11.0
Я не особо приверженец питонов, но мне удалось это сделать:
from os import stat
from pwd import getpwuid
def find_owner(filename):
return getpwuid(stat(filename).st_uid).pw_name
Вот пример кода, показывающий, как можно найти владельца файла:
#!/usr/bin/env python
import os
import pwd
filename = '/etc/passwd'
st = os.stat(filename)
uid = st.st_uid
print(uid)
# output: 0
userinfo = pwd.getpwuid(st.st_uid)
print(userinfo)
# output: pwd.struct_passwd(pw_name='root', pw_passwd='x', pw_uid=0,
# pw_gid=0, pw_gecos='root', pw_dir='/root', pw_shell='/bin/bash')
ownername = pwd.getpwuid(st.st_uid).pw_name
print(ownername)
# output: root
Вы хотите использовать os.stat ()
:
os.stat(path)
Perform the equivalent of a stat() system call on the given path.
(This function follows symlinks; to stat a symlink use lstat().)
The return value is an object whose attributes correspond to the
members of the stat structure, namely:
- st_mode - protection bits,
- st_ino - inode number,
- st_dev - device,
- st_nlink - number of hard links,
- st_uid - user id of owner,
- st_gid - group id of owner,
- st_size - size of file, in bytes,
- st_atime - time of most recent access,
- st_mtime - time of most recent content modification,
- st_ctime - platform dependent; time of most recent metadata
change on Unix, or the time of creation on Windows)
Пример использования для получения UID владельца:
from os import stat
stat(my_filename).st_uid
Обратите внимание, однако, что stat
возвращает номер идентификатора пользователя (например, 0 для root), а не фактическое имя пользователя.
st_uid
, который является идентификатором пользователя владельца. Затем вам нужно преобразовать его в имя. Для этого используйте pwd.getpwuid . Вы хотите использовать os.stat ()
:
os.stat(path)
Perform the equivalent of a stat() system call on the given path.
(This function follows symlinks; to stat a symlink use lstat().)
The return value is an object whose attributes correspond to the
members of the stat structure, namely:
- st_mode - protection bits,
- st_ino - inode number,
- st_dev - device,
- st_nlink - number of hard links,
- st_uid - user id of owner,
- st_gid - group id of owner,
- st_size - size of file, in bytes,
- st_atime - time of most recent access,
- st_mtime - time of most recent content modification,
- st_ctime - platform dependent; time of most recent metadata
change on Unix, or the time of creation on Windows)
Пример использования для получения UID владельца:
from os import stat
stat(my_filename).st_uid
Обратите внимание, однако, что stat
возвращает номер идентификатора пользователя (например, 0 для root), а не фактическое имя пользователя.