Back To Basics: Getting File Information Using Perl’s Stat Function

Written By
Web Webster
Web Webster
Feb 26, 2009

[ Thanks to Mike
Golvach
for this link. ]

“Today we’re going to take a brief introductory look at
Perl’s stat() function and how you can use it to extract lots of
useful information from files, directories, etc (actually,
everything in Linux/Unix is a “file” of a certain type). It’s
incredibly easy to use and, even if you’ve never used Perl before,
very easy to implement. If you’re still stuck at the Shebang line
in point of reference to Perl/shell scripting, check out that post,
as we hope it provides a good base for one of the things you’re
most likely to find in a Perl or shell script. It also goes beyond
just scripting and attacks some other basic concepts.

“Here’s a very simple Perl script (which, as demonstrated, can
be written on the command line as well) that will let you know the
user id and group id associated with a particular file. We won’t be
exploring stat() completely in this post. just enough to get you
started and comfortable (you could get the same information by
running “ls -l” instead of just “ls,” but that would defeat the
purpose, right? ;):”


Complete Story

Web Webster

Web Webster

Web Webster has more than 20 years of writing and editorial experience in the tech sector. He’s written and edited news, demand generation, user-focused, and thought leadership content for business software solutions, consumer tech, and Linux Today, he edits and writes for a portfolio of tech industry news and analysis websites including webopedia.com, and DatabaseJournal.com.

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.