Chapter 25. 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. If this is a number, it must be in octal, e.g., 0644.

chown list

Changes the owner and group of a list of files. The first two elements of the list must be the numerical user id and group id. If either is –1, that property is not changed.

link oldfile, newfile

Creates a new filename linked to the old file.

lstat file

Like stat, but if the last component of the filename is a symbolic link, stats the link instead of the file it links to. file can be an expression evaluating to a filename, or _ to refer to the last file test -l operation or lstat call.

mkdir dir [ , perm ]

Creates a directory with permissions specified by perm and modified by the current umask. If perm is a number, it must be an octal number. Default value for perm is 0777. See also umask.

readlink expr

Returns the name of the file pointed to by the symbolic link designated by expr.

rename oldname, newname

Changes the name of a file.

rmdir expr

Deletes the directory if it is empty.

stat file

Returns a 13-element list with file information. file can be a filehandle, an expression evaluating to a filename, or _ to refer to the last file test operation or stat call. Returns an empty list if the stat fails.

Use the standard module File::stat for by-name access to the elements of the list:

Index

Name

Description ...

Get Perl Pocket Reference, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.