天天看點

OS子產品的常用内置方法

chdir

修改目前工作目錄到指定目錄
Change the current working directory to the specified path.           

chmod

修改一個檔案的通路權限
Change the access permissions of a file.           

chown

把一個目錄的屬主和屬組修改成另一個數字的屬主和屬組
Change the owner and group id of path to the numeric uid and gid           

chroot

修改根目錄(在liunx下使用)
Change root directory to path.           

ctermid

傳回一個程序的控制台的名字
Return the name of the controlling terminal for this process.           

getcwd

以字元串格式顯示目前工作目錄(python解釋器的工作目錄)
Return a unicode string representing the current working directory.           

getegid

擷取目前程序的有效組ID
Return the current process's effective group id.           

getenv

擷取系統的環境變量,環境變量不存在時傳回None
Get an environment variable, return None if it doesn't exist.           

geteuid

擷取目前程序的有效使用者ID
Return the current process's effective user id.           

getgid

擷取當彰程序的組ID
Return the current process's group id.           

getgrouplist

傳回指定使用者的基本組的清單
getgrouplist(user, group) -> list of groups to which a user belongs
Returns a list of groups to which a user belongs.           

getgroups

擷取一個程序的附加組ID的清單
Return list of supplemental group IDs for the process.           

getloadavg

傳回目前一個由系統1分鐘,5分鐘和15分鐘的平均負載使用率組成的元組
Return average recent system load information.
Return the number of processes in the system run queue averaged over
the last 1, 5, and 15 minutes as a tuple of three floats.
Raises OSError if the load average was unobtainable.           

getlogin

傳回目前系統的實際登陸的使用者名
Return the actual login name.           

getpid

傳回目前的程序ID号
Return the current process id.           

getppid

傳回目前程序的父程序的ID号
Return the parent's process id.           

getuid

傳回目前程序的使用者ID
Return the current process's user id.           

kill

結束一個程序
Kill a process with a signal.           

killpg

結束掉一個程序組
Kill a process group with a signal.           

listdir

傳回指定路徑下由所有所有檔案的名字組成的清單,未指定路徑則預設為目前路徑
Return a list containing the names of the files in the directory.
path can be specified as either str or bytes.  If path is bytes,
  the filenames returned will also be bytes; in all other circumstances
  the filenames returned will be str.
If path is None, uses the path='.'.           

lseek

設定并傳回指定檔案的指針的位置,
Set the position of a file descriptor.  Return the new position.
Return the new cursor position in number of bytes
relative to the beginning of the file.           

major

擷取一個裝置檔案的主裝置号
Extracts a device major number from a raw device number.           

makedev

在系統上建立一個新的裝置檔案
Composes a raw device number from the major and minor device numbers.           

makedirs

遞歸建立多層目錄,如果目标目錄已經存在,則報錯
Super-mkdir; create a leaf directory and all intermediate ones.  Works like
mkdir, except that any intermediate path segment (not just the rightmost)
will be created if it does not exist. If the target directory already
exists, raise an OSError if exist_ok is False. Otherwise no exception is
raised.  This is recursive.           

minor

擷取一個裝置檔案的次裝置号
Extracts a device minor number from a raw device number.           

mkdir

建立一個目錄
Create a directory.           

mkfifo

建立一個管道檔案
If dir_fd is not None, it should be a file descriptor open to a directory,
  and path should be relative; path will then be relative to that directory.
dir_fd may not be implemented on your platform.
  If it is unavailable, using it will raise a NotImplementedError.           

nice

為一個程序增加屬性,也即修改一個程序的nice值
Add increment to the priority of process and return the new priority.           

open

在硬體層面打開檔案,傳回一個整型的檔案描述符
Open a file for low level IO.  Returns a file descriptor (integer).           

putenv

修改或增加一個環境變量
Change or add an environment variable.           

read

讀取指定檔案的檔案描述符,傳回位元組對象
Read from a file descriptor.  Returns a bytes object.           

remove

删除指定檔案
Remove a file (same as unlink()).           

removedirs

删除多層目錄,
Super-rmdir; remove a leaf directory and all empty intermediate
ones.  Works like rmdir except that, if the leaf directory is
successfully removed, directories corresponding to rightmost path
segments will be pruned away until either the whole path is
consumed or an error occurs.  Errors during this latter phase are
ignored -- they generally mean that a directory was not empty.           

rename

為一個檔案或目錄重命名
Rename a file or directory.           

rmdir

删除一個目錄
Remove a directory.           

setegid

設定目前程序的有效組ID
Set the current process's effective group id.           

seteuid

設定目前程序的有效使用者ID
Set the current process's effective user id.           

setgid

設定目前程序的組ID
Set the current process's group id.           

setuid

為目前程序設定使用者ID
Set the current process's user id.           

stat

顯示指定路徑的詳細資訊
Perform a stat system call on the given path.           

strerror

把錯誤号碼轉換成資訊字元串
Translate an error code to a message string.           

symlink

為指定目錄建立軟連結
symlink(src, dst, target_is_directory=False, *, dir_fd=None)
Create a symbolic link pointing to src named dst.           

sync

強制寫入内容到磁盤中
Force write of everything to disk.           

system

在子shell中執行系統指令
Execute the command in a subshell.           

times

傳回系統時間資訊的集合
Return a collection containing process timing information.           

umask

為檔案或目錄設定并傳回新權限模式
Set the current numeric umask and return the previous umask.           

uname

傳回目前作業系統的核心資訊
Return an object identifying the current operating system.           

unlink

删除一個軟連結
unlink(path, *, dir_fd=None)
Remove a file (same as remove()).           

unsetenv

删除一個環境變量
Delete an environment variable.           

utime

為指定路徑設定最後通路時間和最後修改時間
utime(path, times=None, *, ns=None, dir_fd=None, follow_symlinks=True)
Set the access and modified time of path.           

walk

給定目錄名,傳回一個由目前目錄名,目前目錄的子目錄以及目前目錄下的普通檔案組成的元組
Directory tree generator.
For each directory in the directory tree rooted at top (including top
itself, but excluding '.' and '..'), yields a 3-tuple
    dirpath, dirnames, filenames
dirpath is a string, the path to the directory.  dirnames is a list of
the names of the subdirectories in dirpath (excluding '.' and '..').
filenames is a list of the names of the non-directory files in dirpath.
Note that the names in the lists are just names, with no path components.
To get a full path (which begins with top) to a file or directory in
dirpath, do os.path.join(dirpath, name).