Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stat vs lstat 2

Status
Not open for further replies.

garymgordon

Programmer
Apr 5, 2000
307
US
As in ...

lstat FILE
Like stat, but does not traverse a final symbolic link.

I am very confused as to exactly how stat and lstat are used ... AND ... the specific difference(s) between them.

Can you, if possible, explain this on a very simplistic basis.

Thanks,
Gary
Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer
 
symbolic links are thingies in file systems where a "file" is actually just an 'address', as in the location of another file. in windows, most of the things on the desktop are just links. when you double-click them, they tell the file system to go to the real location and pretend you had just double-clicked it.
to not traverse a symbolic link would mean that it wouldn't look at the file being pointed to, but instead the actual link "file" (address containing thingy). "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
That helps.

But, how and when would you use these ... and when would you use one (and how/why) and how and why would you use the other.

If you could explain that ... I'd appeciate it.

Thanks!
Gary Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer
 
it just depends on what you want to be 'stat'ing. if you want to evaluate the actual file, it's properties, etc., then use 'stat'. if instead you want to find out about the link itself, when it was created, etc., then use 'lstat'. you'll usually want to use normal stat, just cause symbolic links aren't very interesting or useful. but occasionally, you'll find that you need to know something about a symbolic link...
the how of using them is the same. give it a filename or filehandle, it'll return an array of all the properties of that 'file'. "perldoc -f stat" if you wanna know the contents of that array.
HTH "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
"cause symbolic links aren't very interesting or useful"

I beg your pardon? :)

Well -- they're not what you might call "interesting" I grant you -- but they are useful on occasion. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
They sure ARE useful! How many times in WinDoze have you wished you could put the same file (or directory) into two or more directories without making a copy? Shortcuts might seem one way to do this, but it just isn't the same!
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top