[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: stat question



On Sat, Aug 02, 2003 at 09:07:26AM +0100, David selby wrote:
> A while ago someone suggested using the stat command to get modification 
> times for files etc, ls -al will give the info but I would have to do a 
> lot of string stripping etc ...
> 
> I have looked up man "stat", confusing ... googled for it, confusing ! 
> It is not a regular command, ie "stat" on the command line is a no go 
> though there is a man page for it.

In woody, you need the 'stat' package. In sarge and sid it's part of
coreutils, which everyone has installed. You can use
http://packages.debian.org/ to answer questions like this.

The reason your searches were confusing is that there's also a system
call called stat(), which C programmers care about but which isn't
useful on the command line.

> It appears to be a "pearl" module ?

It's called 'perl', not 'pearl' :-) And no, while there may be a Perl
module with a similar name it's probably not what your respondent was
referring to.

> OK simple question. In a bash script can I use stat to get modification 
> times of files ?
> If so what is the syntax ?

'stat' is a bit tedious for this, because you'd have to parse it out of
the output using sed or something, but it can be done. The most common
use of modification times is to find out whether one file is newer or
older than another, and you do that with '[ file1 -nt file2 ]' and '[
file1 -ot file2 ]' respectively. If it's something else, give us a bit
more detail about what you're trying to do.

Cheers,

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: