11. Document Testing
-op expr if (-e "Filea") {print STDERR ("file1/n"):} file exists.
-B is a block device-C is a character device
-D whether the directory-e file exists
-F whether the normal file-G is set setgid bit
-K whether to set the sticky bit-L as a symbolic connection
-O Whether you own the file-P is a pipe
-R Whether readable-S is not null
-T indicates whether terminal-U sets the setuid bit
-W Whether writable-X is able to execute-Z is an empty file
-A how long before the last visit
-B is a binary file
-C How long is the inode from the last time the file was accessed
-M distance from last modification
-O is only for "real users"
-R whether only "real users" are readable
-S whether socket-t is a text file
-W is only "real user" writable
-X is only "real user" executable
-S returns the length of the file,-a-c-m the number of days returned.
12. File Status
Stat (file): The parameter can be a file name, or a list of file states that can be used as a document handle.
Number name Unix windows
0 Dev Device number c:=2,d:=3
1 Ino index node always 0
2 Mode No
3 Nlink Link Number 0
4 UID File owner 0
5 GID Filegroup 0
6 Rdev Special file information, device type drive letter
7 Size File File size
8 Atime Last access time
9 Mtime Last modified time last modified
CTime inode modification Time file creation time
BLKSZ Disk Block Size 0
Number of blocks in Blocks file 0
Utime (acctime,modtime,filelist): Modifies the timestamp, modifies the access time, and returns the number of files that were successfully modified.
13. File operation
Glob:
@a=glob ("*.txt") returns all file directories that match the pattern, and returns one file at a time if assigned to a simple variable.
The parameter can be a file name or directory.
Can only accept a limited number of files, report too many errors, with the shell to execute.
Because the shell is used to explain execution, it is slow to run.
Another form of @a=<*.txt> is the ancient usage, recommended with Glob.
Truncate (file,lenght): Reduces the length of files to length bytes, if the file length is already less than length,
Don't do anything. Where filename can be a file name, or it can be a variable.
Rename (old,new) successful =1 can be moved from one directory to another, without checking if new is present and potentially destroying the file.
-E "file2″| | Rename (file1,file2) check and move first
14. File Link
Link (file name, link name)
Create links to existing files-hard links, file is linked files, NewLink is created link.
Successful return true, failed to return false.
When you delete one of the two links, you can also access the file by using another.
Synlink Symbolic Link (file name, link name) creates a symbolic link to an existing file, pointing to the file name instead of pointing to the
The file itself, when the original file is deleted (e.g., deleted by the Unlinke function), the created link is not available unless you create
A file with the same name as the original file being linked.
Readlink (linkname) tracks symbolic links, and if linkname is a symbolic link file, returns the file to which it actually points.
Otherwise, an empty string is returned.
Unlink (filelist) = number of files successfully deleted, delete files or files in $_, parameter is List of file names, return value is
The number of files actually deleted.
This function is called unlink instead of delete because it is actually doing a link to delete the file.
XV, Directory operations
Opendir (dirvar,dirname) Open the directory, view the list of files in a directory to open, then operate, then close,
The parameters are:
Dirvar: Directory variable, dirname: directory name, successful return truth, failed to return false.
Closedir (dir): Close directory
Readdir (dir): Returns all files and directories to the array, returns a file or directory for each simple variable, and does not contain the current path.
ChDir (dir): Change directory, run finished return to the original directory, success is true, failure is false.
Telldir (dir): Current directory location
Seekdir (Dir,loc): to the specified location
Rewinddir (dir): The directory location points to the first entry in the directory.
mkdir (dirname,permission): Create directory (current directory, access rights)
RmDir (dirname): Only empty directories can be deleted, and success returns True, and the failure returns false.
16. Summary
1. Concept: descriptor, handle, buffer, access mode, permissions, file status.
2. File access: Open, close, read, write, random access
3. File operation: Test, rename, Intercept, link.
4. Directory operations: the same file.
5. Related technologies: Error functions and variables, file open functions, command line arguments, glob extensions.
Perl Study Notes (ix)--Documents (iv)