Perl Cheat Sheet Page 16

ADVERTISEMENT

17. File test operators
These unary operators take one argument, either a filename or a filehandle, and test
the associated file to see if something is true about it. If the argument is omitted,
they test $_ (except for -t, which tests STDIN ). If the special argument _
(underscore) is passed, they use the info of the preceding test or
call.
stat
File is readable/writable/executable by effective uid/gid.
-r -w -x
File is readable/writable/executable by real uid/gid.
-R -W -X
File is owned by effective/real uid.
-o -O
File exists / has zero size.
-e -z
-s
File exists and has non-zero size. Returns the size.
File is a plain file, a directory.
-f -d
File is a symbolic link, a socket, a named pipe (FIFO).
-l -S -p
File is a block/character special file.
-b -c
File has setuid/setgid/sticky bit set.
-u -g -k
Tests if filehandle ( STDIN by default) is opened to a tty.
-t
-T -B
File is a text/non-text (binary) file. -T and -B return true on a null
file, or a file at EOF when testing a filehandle.
File modification/access/inode-change time. Measured in days.
-M -A -C
Value returned reflects the file age at the time the script started.
See also $ˆT in section ‘Special variables’.
18. File operations
Functions operating on a list of files return the number of files successfully
operated upon.
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
to
.
may be a filename or a filehandle.
FILE
SIZE
FILE
link OLDFILE, NEWFILE
Creates a new filename linked to the old filename.
y
lstat FILE
Like
stat
, but does not traverse a final symbolic link.
mkdir DIR, MODE
Creates a directory with given permissions. Sets $! on failure.
y
readlink EXPR
Returns the value of a symbolic link.
rename OLDNAME, NEWNAME
Changes the name of a file.
y
rmdir FILENAME
Deletes the directory if it is empty. Sets $! on failure.
16

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education