Changeset 391 for python/trunk/Doc/library/stat.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/stat.rst
r2 r391 1 2 :mod:`stat` --- Interpreting :func:`stat` results 3 ================================================= 1 :mod:`stat` --- Interpreting :func:`~os.stat` results 2 ===================================================== 4 3 5 4 .. module:: stat … … 7 6 .. sectionauthor:: Skip Montanaro <skip@automatrix.com> 8 7 8 **Source code:** :source:`Lib/stat.py` 9 10 -------------- 9 11 10 12 The :mod:`stat` module defines constants and functions for interpreting the 11 13 results of :func:`os.stat`, :func:`os.fstat` and :func:`os.lstat` (if they 12 exist). For complete details about the :c func:`stat`, :cfunc:`fstat` and13 :c func:`lstat` calls, consult the documentation for your system.14 exist). For complete details about the :c:func:`stat`, :c:func:`fstat` and 15 :c:func:`lstat` calls, consult the documentation for your system. 14 16 15 17 The :mod:`stat` module defines the following functions to test for specific file … … 69 71 Normally, you would use the :func:`os.path.is\*` functions for testing the type 70 72 of a file; the functions here are useful when you are doing multiple tests of 71 the same file and wish to avoid the overhead of the :c func:`stat` system call73 the same file and wish to avoid the overhead of the :c:func:`stat` system call 72 74 for each test. These are also useful when checking for information about a file 73 75 that isn't handled by :mod:`os.path`, like the tests for block and character 74 76 devices. 75 77 76 All the variables below are simply symbolic indexes into the 10-tuple returned77 by :func:`os.stat`, :func:`os.fstat` or :func:`os.lstat`.78 79 80 .. data:: ST_MODE81 82 Inode protection mode.83 84 85 .. data:: ST_INO86 87 Inode number.88 89 90 .. data:: ST_DEV91 92 Device inode resides on.93 94 95 .. data:: ST_NLINK96 97 Number of links to the inode.98 99 100 .. data:: ST_UID101 102 User id of the owner.103 104 105 .. data:: ST_GID106 107 Group id of the owner.108 109 110 .. data:: ST_SIZE111 112 Size in bytes of a plain file; amount of data waiting on some special files.113 114 115 .. data:: ST_ATIME116 117 Time of last access.118 119 120 .. data:: ST_MTIME121 122 Time of last modification.123 124 125 .. data:: ST_CTIME126 127 The "ctime" as reported by the operating system. On some systems (like Unix) is128 the time of the last metadata change, and, on others (like Windows), is the129 creation time (see platform documentation for details).130 131 The interpretation of "file size" changes according to the file type. For plain132 files this is the size of the file in bytes. For FIFOs and sockets under most133 flavors of Unix (including Linux in particular), the "size" is the number of134 bytes waiting to be read at the time of the call to :func:`os.stat`,135 :func:`os.fstat`, or :func:`os.lstat`; this can sometimes be useful, especially136 for polling one of these special files after a non-blocking open. The meaning137 of the size field for other character and block devices varies more, depending138 on the implementation of the underlying system call.139 140 The variables below define the flags used in the :data:`ST_MODE` field.141 142 Use of the functions above is more portable than use of the first set of flags:143 144 .. data:: S_IFMT145 146 Bit mask for the file type bit fields.147 148 .. data:: S_IFSOCK149 150 Socket.151 152 .. data:: S_IFLNK153 154 Symbolic link.155 156 .. data:: S_IFREG157 158 Regular file.159 160 .. data:: S_IFBLK161 162 Block device.163 164 .. data:: S_IFDIR165 166 Directory.167 168 .. data:: S_IFCHR169 170 Character device.171 172 .. data:: S_IFIFO173 174 FIFO.175 176 The following flags can also be used in the *mode* argument of :func:`os.chmod`:177 178 .. data:: S_ISUID179 180 Set UID bit.181 182 .. data:: S_ISGID183 184 Set-group-ID bit. This bit has several special uses. For a directory185 it indicates that BSD semantics is to be used for that directory:186 files created there inherit their group ID from the directory, not187 from the effective group ID of the creating process, and directories188 created there will also get the :data:`S_ISGID` bit set. For a189 file that does not have the group execution bit (:data:`S_IXGRP`)190 set, the set-group-ID bit indicates mandatory file/record locking191 (see also :data:`S_ENFMT`).192 193 .. data:: S_ISVTX194 195 Sticky bit. When this bit is set on a directory it means that a file196 in that directory can be renamed or deleted only by the owner of the197 file, by the owner of the directory, or by a privileged process.198 199 .. data:: S_IRWXU200 201 Mask for file owner permissions.202 203 .. data:: S_IRUSR204 205 Owner has read permission.206 207 .. data:: S_IWUSR208 209 Owner has write permission.210 211 .. data:: S_IXUSR212 213 Owner has execute permission.214 215 .. data:: S_IRWXG216 217 Mask for group permissions.218 219 .. data:: S_IRGRP220 221 Group has read permission.222 223 .. data:: S_IWGRP224 225 Group has write permission.226 227 .. data:: S_IXGRP228 229 Group has execute permission.230 231 .. data:: S_IRWXO232 233 Mask for permissions for others (not in group).234 235 .. data:: S_IROTH236 237 Others have read permission.238 239 .. data:: S_IWOTH240 241 Others have write permission.242 243 .. data:: S_IXOTH244 245 Others have execute permission.246 247 .. data:: S_ENFMT248 249 System V file locking enforcement. This flag is shared with :data:`S_ISGID`:250 file/record locking is enforced on files that do not have the group251 execution bit (:data:`S_IXGRP`) set.252 253 .. data:: S_IREAD254 255 Unix V7 synonym for :data:`S_IRUSR`.256 257 .. data:: S_IWRITE258 259 Unix V7 synonym for :data:`S_IWUSR`.260 261 .. data:: S_IEXEC262 263 Unix V7 synonym for :data:`S_IXUSR`.264 265 78 Example:: 266 79 … … 274 87 for f in os.listdir(top): 275 88 pathname = os.path.join(top, f) 276 mode = os.stat(pathname) [ST_MODE]89 mode = os.stat(pathname).st_mode 277 90 if S_ISDIR(mode): 278 91 # It's a directory, recurse into it … … 291 104 walktree(sys.argv[1], visitfile) 292 105 106 All the variables below are simply symbolic indexes into the 10-tuple returned 107 by :func:`os.stat`, :func:`os.fstat` or :func:`os.lstat`. 108 109 110 .. data:: ST_MODE 111 112 Inode protection mode. 113 114 115 .. data:: ST_INO 116 117 Inode number. 118 119 120 .. data:: ST_DEV 121 122 Device inode resides on. 123 124 125 .. data:: ST_NLINK 126 127 Number of links to the inode. 128 129 130 .. data:: ST_UID 131 132 User id of the owner. 133 134 135 .. data:: ST_GID 136 137 Group id of the owner. 138 139 140 .. data:: ST_SIZE 141 142 Size in bytes of a plain file; amount of data waiting on some special files. 143 144 145 .. data:: ST_ATIME 146 147 Time of last access. 148 149 150 .. data:: ST_MTIME 151 152 Time of last modification. 153 154 155 .. data:: ST_CTIME 156 157 The "ctime" as reported by the operating system. On some systems (like Unix) is 158 the time of the last metadata change, and, on others (like Windows), is the 159 creation time (see platform documentation for details). 160 161 The interpretation of "file size" changes according to the file type. For plain 162 files this is the size of the file in bytes. For FIFOs and sockets under most 163 flavors of Unix (including Linux in particular), the "size" is the number of 164 bytes waiting to be read at the time of the call to :func:`os.stat`, 165 :func:`os.fstat`, or :func:`os.lstat`; this can sometimes be useful, especially 166 for polling one of these special files after a non-blocking open. The meaning 167 of the size field for other character and block devices varies more, depending 168 on the implementation of the underlying system call. 169 170 The variables below define the flags used in the :data:`ST_MODE` field. 171 172 Use of the functions above is more portable than use of the first set of flags: 173 174 .. data:: S_IFSOCK 175 176 Socket. 177 178 .. data:: S_IFLNK 179 180 Symbolic link. 181 182 .. data:: S_IFREG 183 184 Regular file. 185 186 .. data:: S_IFBLK 187 188 Block device. 189 190 .. data:: S_IFDIR 191 192 Directory. 193 194 .. data:: S_IFCHR 195 196 Character device. 197 198 .. data:: S_IFIFO 199 200 FIFO. 201 202 The following flags can also be used in the *mode* argument of :func:`os.chmod`: 203 204 .. data:: S_ISUID 205 206 Set UID bit. 207 208 .. data:: S_ISGID 209 210 Set-group-ID bit. This bit has several special uses. For a directory 211 it indicates that BSD semantics is to be used for that directory: 212 files created there inherit their group ID from the directory, not 213 from the effective group ID of the creating process, and directories 214 created there will also get the :data:`S_ISGID` bit set. For a 215 file that does not have the group execution bit (:data:`S_IXGRP`) 216 set, the set-group-ID bit indicates mandatory file/record locking 217 (see also :data:`S_ENFMT`). 218 219 .. data:: S_ISVTX 220 221 Sticky bit. When this bit is set on a directory it means that a file 222 in that directory can be renamed or deleted only by the owner of the 223 file, by the owner of the directory, or by a privileged process. 224 225 .. data:: S_IRWXU 226 227 Mask for file owner permissions. 228 229 .. data:: S_IRUSR 230 231 Owner has read permission. 232 233 .. data:: S_IWUSR 234 235 Owner has write permission. 236 237 .. data:: S_IXUSR 238 239 Owner has execute permission. 240 241 .. data:: S_IRWXG 242 243 Mask for group permissions. 244 245 .. data:: S_IRGRP 246 247 Group has read permission. 248 249 .. data:: S_IWGRP 250 251 Group has write permission. 252 253 .. data:: S_IXGRP 254 255 Group has execute permission. 256 257 .. data:: S_IRWXO 258 259 Mask for permissions for others (not in group). 260 261 .. data:: S_IROTH 262 263 Others have read permission. 264 265 .. data:: S_IWOTH 266 267 Others have write permission. 268 269 .. data:: S_IXOTH 270 271 Others have execute permission. 272 273 .. data:: S_ENFMT 274 275 System V file locking enforcement. This flag is shared with :data:`S_ISGID`: 276 file/record locking is enforced on files that do not have the group 277 execution bit (:data:`S_IXGRP`) set. 278 279 .. data:: S_IREAD 280 281 Unix V7 synonym for :data:`S_IRUSR`. 282 283 .. data:: S_IWRITE 284 285 Unix V7 synonym for :data:`S_IWUSR`. 286 287 .. data:: S_IEXEC 288 289 Unix V7 synonym for :data:`S_IXUSR`. 290 291 The following flags can be used in the *flags* argument of :func:`os.chflags`: 292 293 .. data:: UF_NODUMP 294 295 Do not dump the file. 296 297 .. data:: UF_IMMUTABLE 298 299 The file may not be changed. 300 301 .. data:: UF_APPEND 302 303 The file may only be appended to. 304 305 .. data:: UF_OPAQUE 306 307 The directory is opaque when viewed through a union stack. 308 309 .. data:: UF_NOUNLINK 310 311 The file may not be renamed or deleted. 312 313 .. data:: UF_COMPRESSED 314 315 The file is stored compressed (Mac OS X 10.6+). 316 317 .. data:: UF_HIDDEN 318 319 The file should not be displayed in a GUI (Mac OS X 10.5+). 320 321 .. data:: SF_ARCHIVED 322 323 The file may be archived. 324 325 .. data:: SF_IMMUTABLE 326 327 The file may not be changed. 328 329 .. data:: SF_APPEND 330 331 The file may only be appended to. 332 333 .. data:: SF_NOUNLINK 334 335 The file may not be renamed or deleted. 336 337 .. data:: SF_SNAPSHOT 338 339 The file is a snapshot file. 340 341 See the \*BSD or Mac OS systems man page :manpage:`chflags(2)` for more information. 342
Note:
See TracChangeset
for help on using the changeset viewer.