Information on Files

There are various ways of finding out information on files, some are wrappers around regular expressions, others are wrappers around system calls.

Directories

Moving around in the hierarchy.
cd ?dirName?

Changes the current working directory to dirName, or the home directory (as given by the HOME environment variable) if dirName isn't given. Returns an empty string.

pwd

Returns the full path name of the current working directory.

Names

These procedures make manipulating file names easier.
glob ?-nocomplain? ?--? pattern ?pattern ...?

Returns a list of the names of all files that match any of the pattern arguments (special characters ?, *, [], {}, and \). If -nocomplain isn't specified, an error occurs if the return list would be empty.

file dirname name

Returns all of the characters in name up to but not including the last / character. Returns . if name contatins no slashes, / if the last slash in name is its first character.

file rootname name

Returns all of the characters in name up to but not including the last character. Returns name if it doesn't contain any dots or it it doesn't contain any dots after the last slash.

file tail name

Returns all of the characters in name after the last / character. Returns name if it contains no slashes.

file extension name

Returns all of the characters in name after and including the last dot. Returns an empty string if there is no dot in name or no dot after the last slash in name.

Permissions

Used for checking the permissions on files.
file exists name

Returns 1 if name exists and the current user has seach privilege for the directories leading to it, 0 otherwise.

file executable name

Returns 1 if name is executable by the current user, 0 otherwise.

file owned named

Returns 1 if name is owned by the current user, 0 otherwise.

file readable name

Returns 1 if name is readable by the current user, 0 otherwise.

file writable name

Returns 1 if name is writable by the current user, 0 otherwise.

Types

Finding out the types of files.
file type name

Returns a string giving the type of the file name. The return value will be one of file, directory, characterSpecial, blockSpecial, fifo, link, socket.

file isdirectory name

Returns 1 if name is a directory, 0 otherwise.

file isfile name

Returns 1 if name is a file, 0 otherwise.

Meta Data

All the other stuff about a file.
file size name

Returns a decimal string giving the size of the file name in bytes.

file stat name arrayName

Invokes stat system call on name and sets elements of arrayName to hold information returned by stat. The following elements are set, each as a deciamal string: atime, ctime, dev, gid, ino, mode, mtime, nlink, size, and uid.

file lstat name arrayName

Invokes the lstat system call on name and sets elements of arrayName to hold information returned by lstat. This option is identical to the stat option unless name refers to a symbolic link, in which case this command returns information about the link instead of the file to which it points.

file atime name

Returns a decimal string giving the time at which file name was last accessed, measured in seconds from 12:00 A.M. on January 1, 1970.

file mtime name

Returns a decimal string giving the time at which file name was last modified, measuered in seconds from 12:00 A.M. on January 1, 1970.

file readlink name

Returns the value of the symbolic link given by name (the name of the file to which it points).


Previous Contents Next
Clinton Roy