Perl File/Dir Operations
File Test Operators
|
File Operations
chmod LIST | Changes the permissions of a list of files. The first element of the list must be the numerical mode. |
chown LIST | Changes the owner and group of a list of files. The first two elements of the list must be the numerical uid and gid. |
truncate FILE, SIZE | Truncates FILE to SIZE. FILE may be a filename or a filehandle. |
link OLDFILE, NEWFILE | Creates a new filename linked to the old filename. |
lstat FILE | Like stat, but does not traverse a final symbolic link. |
mkdir DIR, MODE | Creates a directory with given permissions. Sets $! on failure. |
readlink EXPR | Returns the value of a symbolic link. |
rename OLDNAME, NEWNAME | Changes the name of a file. |
rmdir NAME | Deletes the directory if it is empty. Sets $! on failure. |
stat FILE | Returns a 13-element array (0: $dev, 1: $ino, 2: $mode, 3: $nlink, 4: $uid, 5: $gid, 6: $rdev, 7: $size, 8: $atime, 9: $mtime, 10: $ctime, 11: $blksize, 12: $blocks). FILE can be a filehandle, an expression evaluating to a filename, or _ to refer to the last file test operation or stat call. Returns a null list if the stat fails. |
symlink OLDFILE, NEWFILE | Creates a new filename symbolically linked to the old filename. |
unlink LIST | Deletes a list of files. |
utime LIST | Changes the access and modification times. The first two elements of the list must be the numerical access and modification times. |
The following filename conventions apply when opening a file.
“FILE” open FILE for input. also “<FILE”.
“>FILE” open FILE for output, creating it if necessary.
open(LOG,”>$access_log”) || die “Can’t open User Access Log: $!\n”;
“>>FILE” open FILE in append mode. open(LOG,”>>$access_log”);
“+<FILE” open FILE with read/write access (file must exist).
“+>FILE” open FILE with read/write access (file truncated).
“|CMD” opens a pipe to command CMD; forks if CMD is. open(LOG,”| ausgabe”);
“CMD|” opens a pipe from command CMD; forks if CMD is.
open(LOG,”eingabe |”);
open(DATUM,”date |”);
open(WORT,”| wc > wort.dat”); # wc : counter
Leave a Reply