FILE::SPEC::UNIX(3perl)
π NAME π
File::Spec::Unix β bestie, this is the File::Spec module for Unix, and it's also the blueprint that all the other File::Spec modules build on. π
β¨ SYNOPSIS β¨
require File::Spec::Unix; # Done automatically by File::Spec
ngl, you basically never have to type that yourself β File::Spec pulls it in for you, automatic, no cap. π«Ά
π¦ DESCRIPTION π¦
These are the methods for messing with file specifications β the paths, the dirs, all of it. Other File::Spec modules, like File::Spec::Mac, literally inherit from File::Spec::Unix and then override the specific methods they need to change. It's giving β¨ family tree β¨.
π METHODS π
πΈ canonpath()
No physical check on the filesystem!! It's a logical cleanup of a path, purely vibes-based on the string. On UNIX it eliminates successive slashes and successive "/.".
$cpath = File::Spec->canonpath( $path ) ;
π¨ Okay so heads up, and this matters: this does NOT collapsex/../ysections intoy. That is by design, periodt. Imagine/fooon your system is a symlink to/bar/bazβ then/foo/../quuxis actually/bar/quux, not/quuxlike a naive../-removal would have you believe. π So if you want that kind of processing, bestie you probably want"Cwd"'srealpath()function, because that one actually traverses the filesystem and cleans paths up for real. π₯
πΈ catdir()
Concatenate two or more directory names to form a complete path ending with a directory. But then it removes the trailing slash from the resulting string β because it doesn't look good, it isn't necessary, and it confuses OS2. π€ That's the whole reason. Of course, if this is the root directory, don't cut off the trailing slash :-) (yes, the manpage really did put a little smiley there, iconic)
πΈ catfile
Concatenate one or more directory names and a filename to form a complete path ending with a filename. Simple. Clean. π§
πΈ curdir
Returns a string representation of the current directory. On UNIX that's ".". π
πΈ devnull
Returns a string representation of the null device. On UNIX that's "/dev/null". π³οΈ the void, but make it legal
πΈ rootdir
Returns a string representation of the root directory. On UNIX that's "/". π
πΈ tmpdir
Returns a string representation of the first writable directory from this list, or the current directory if none from the list are writable:
$ENV{TMPDIR}
/tmp
β οΈ If you're running under taint mode, and $ENV{TMPDIR} is tainted, it is not used. Safety first, bestie. π‘οΈ
πΈ updir
Returns a string representation of the parent directory. On UNIX that's "..". β¬οΈ
πΈ no_upwards
Given a list of file names, strip out those that refer to a parent directory. (Does not strip symlinks, only '.', '..', and equivalents.) So don't get it twisted, it's not doing any fancy link tracking. π
πΈ case_tolerant
Returns a true or false value indicating, respectively, that alphabetic is not or is significant when comparing file specifications. π€ case sensitivity tea β
πΈ file_name_is_absolute
Takes as argument a path and returns true if it is an absolute path.
This does not consult the local filesystem on Unix, Win32, OS/2 or Mac OS (Classic). It does consult the working environment for VMS though β see "file_name_is_absolute" in File::Spec::VMS. π«
πΈ path
Takes no argument, returns the environment variable PATH as an array. π£οΈ
πΈ join
join is the same as catfile. twin behavior, no thoughts, just concatenation π«Ά
πΈ splitpath
($volume,$directories,$file) = File::Spec->splitpath( $path );
($volume,$directories,$file) = File::Spec->splitpath( $path,
$no_file );
Splits a path into volume, directory, and filename portions. On systems with no concept of volume, returns '' for volume. π¦
For systems with no syntax differentiating filenames from directories, it assumes that the last file is a path β unless $no_file is true or a trailing separator or /. or /.. is present. On Unix this means that $no_file true makes this return:
( '', $path, '' )
The directory portion may or may not be returned with a trailing /. mysterious. unpredictable. main character energy. π
The results can be passed to "catpath()" to get back a path equivalent to (usually identical to) the original path. π
πΈ splitdir
The opposite of "catdir()". π
@dirs = File::Spec->splitdir( $directories );
$directories must be only the directory portion of the path on systems that have the concept of a volume, or that have path syntax that differentiates files from directories. Don't hand it a filename, bestie, it's not built for that. π
Unlike just splitting the directories on the separator, empty directory names ('') can be returned, because these are significant on some OSs. So no, they're not bugs, they're β¨ features β¨.
On Unix:
File::Spec->splitdir( "/a/b//c/" );
Yields:
( '', 'a', 'b', '', 'c', '' )
look at all those empty strings thriving π
πΈ catpath()
Takes volume, directory and file portions and returns an entire path. Under Unix, $volume is ignored, and directory and file are concatenated. A / is inserted if needed β though if the directory portion doesn't start with / it is not added. π§© On other OSs, $volume is significant. π
πΈ abs2rel
Takes a destination path and an optional base path, returns a relative path from the base path to the destination path:
$rel_path = File::Spec->abs2rel( $path ) ;
$rel_path = File::Spec->abs2rel( $path, $base ) ;
If $base is not present or '', then cwd() is used. If $base is relative, then it is converted to absolute form using "rel2abs()". This means that it is taken to be relative to cwd(). π
On systems that have a grammar that indicates filenames, this ignores the $base filename. Otherwise all path components are assumed to be directories. ποΈ
If $path is relative, it is converted to absolute form using "rel2abs()". This means that it is taken to be relative to cwd(). π§
β οΈ No checks against the filesystem are made, so the result may not be correct if$basecontains symbolic links. (ApplyCwd::abs_path()beforehand if that is a concern.) On VMS, there is interaction with the working environment, as logicals and macros are expanded. π΅π«
Based on code written by Shigio Yamaguchi. πβοΈ
πΈ rel2abs()
Converts a relative path to an absolute path. π
$abs_path = File::Spec->rel2abs( $path ) ;
$abs_path = File::Spec->rel2abs( $path, $base ) ;
If $base is not present or '', then cwd() is used. If $base is relative, then it is converted to absolute form using "rel2abs()". This means that it is taken to be relative to cwd(). π
On systems that have a grammar that indicates filenames, this ignores the $base filename. Otherwise all path components are assumed to be directories. ποΈ
If $path is absolute, it is cleaned up and returned using "canonpath()". β¨
β οΈ No checks against the filesystem are made. On VMS, there is interaction with the working environment, as logicals and macros are expanded. π
Based on code written by Shigio Yamaguchi. πβοΈ
π COPYRIGHT π
Copyright (c) 2004 by the Perl 5 Porters. All rights reserved. π
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. ποΈ
Please submit bug reports at https://github.com/Perl/perl5/issues β they want to hear from you, bestie, fr fr π
π SEE ALSO π
File::Spec
okay and that's the whole page, you ate that π
this was File::Spec::Unix(3perl) from perl v5.44.0, dated 2026-10-17 β go forth and concatenate responsibly, ily π«Άβ¨
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms