Kolko casov suboru pozna FreeBSD?

Jozef Drahovsky freebsdcz2 at jozef.drahovsky.sk
Sat Mar 16 11:38:38 CET 2019


Ahoje.

Hram sa s casmi suboru v php a perl, vratene uchovania a obnovy datumu v 
tar suboroch a ci zapis do suboru alebo start programu zmeni access time 
a kedy.
Zo zaciatku som mal v tom jasno, potom prisli pochybnosti a az teraz 
zacinam do toho znova aspon trochu vidiet.

Velmi sa mi to podoba na stary vtip: Z kolkych casti sa sklada puska? 
Puska sa zklada zo 4 casti, su to tieto tri, pazba a hlaven.

Prikaz ls vie zobrazit dva casy:
ls -lT   zobrazi last modification time
ls -lTu  zobrazi last access time

Perl a php pozna tri casy:
atime    last access time in seconds since the epoch
mtime    last modify time in seconds since the epoch
ctime    inode change time in seconds since the epoch

Prikaz stat zobrazuje styri casy:
st_atime, st_mtime, st_ctime, st_birthtime

Nie vsetko sa da vycitat z manualnov, nieco si treba aj otestovat.
Na ozrejmenie suvislosti som spravil jednoduchy program v perle a script.
Na zaver mailu je vysledok testovana.
Ak mate chut, skuste odpovedat na otazku:
1,Aky je to cas st_birthtime a jeho vyznam?

--- file timemark ---
#!/usr/bin/perl
# Ger Timemark
sub timemark
{ my $t=$_[0];
  ($lsec,$lmin,$lhour,$lday,$lmon,$lyear,$lwday,$lyday,$lisdst)=localtime($t); # transfer 4 Local Time
   $lyear=$lyear+1900; $lmon=$lmon+1;
   $tmark=sprintf 
"%4.4d-%2.2d-%2.2d-%2.2d-%2.2d-%2.2d",$lyear,$lmon,$lday,$lhour,$lmin,$lsec;
   return $tmark;
}
$file=@ARGV[0];
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)= 
stat($file);
# print "dev=$dev, ino=$ino, mode=$mode, nlink=$nlink, uid=$uid, 
gid=$gid, rdev=$rdev, size=$size, atime=$atime, mtime=$mtime, 
ctime=$ctime, blksize=$blksize, blocks=$blocks\n";
print "file=$file size=$size atime=" . timemark($atime) .  " mtime=" . 
timemark($mtime) .  " ctime=" . timemark($ctime) . "\n";
exit(0);

--- file go ---
#!/bin/sh
rm experiment
echo "1. create file extperiment"
touch experiment
echo "ls comand with last modification time and last access time"
ls -lT experiment
ls -lTu experiment
./timemark experiment
stat experiment
sleep 4

echo
echo "2. add line to file experiment"
echo "#/bin/sh" >>experiment
echo "echo I am experiment in time" >>experiment
echo "stat experiment" >>experiment
echo "ls comand with last modification time and last access time"
ls -lT experiment
ls -lTu experiment
./timemark experiment
stat experiment
sleep 4

echo
echo "3. file experiment tar, delete and un tar"
tar cvf experiment.tar experiment
rm experiment
tar xvf experiment.tar
echo "ls comand with last modification time and last access time"
ls -lT experiment
ls -lTu experiment
./timemark experiment
stat experiment
sleep 4

echo
echo "4. change parmeter to file experiment"
chmod +x experiment
echo "ls comand with last modification time and last access time"
ls -lT experiment
ls -lTu experiment
./timemark experiment
stat experiment
sleep 4

echo
echo "5. run file experiment"
./experiment
echo "ls comand with last modification time and last access time"
ls -lT experiment
ls -lTu experiment
./timemark experiment
stat experiment
exit

--- vypis casov ---
# ./go
1. create file extperiment
ls comand with last modification time and last access time
-rw-r--r--  1 root  www  0 Mar 16 11:06:23 2019 experiment
-rw-r--r--  1 root  www  0 Mar 16 11:06:23 2019 experiment
file=experiment size=0 atime=2019-03-16-11-06-23 
mtime=2019-03-16-11-06-23 ctime=2019-03-16-11-06-23
95 1846261 -rw-r--r-- 1 root www 0 0 "Mar 16 11:06:23 2019" "Mar 16 
11:06:23 2019" "Mar 16 11:06:23 2019" "Mar 16 11:06:23 2019" 32768 0 0 
experiment

2. add line to file experiment
ls comand with last modification time and last access time
-rw-r--r--  1 root  www  54 Mar 16 11:06:27 2019 experiment
-rw-r--r--  1 root  www  54 Mar 16 11:06:23 2019 experiment
file=experiment size=54 atime=2019-03-16-11-06-23 
mtime=2019-03-16-11-06-27 ctime=2019-03-16-11-06-27
95 1846261 -rw-r--r-- 1 root www 3697930 54 "Mar 16 11:06:23 2019" "Mar 
16 11:06:27 2019" "Mar 16 11:06:27 2019" "Mar 16 11:06:23 2019" 32768 8 
0 experiment

3. file experiment tar, delete and un tar
a experiment
x experiment
ls comand with last modification time and last access time
-rw-r--r--  1 root  www  54 Mar 16 11:06:27 2019 experiment
-rw-r--r--  1 root  www  54 Mar 16 11:06:31 2019 experiment
file=experiment size=54 atime=2019-03-16-11-06-31 
mtime=2019-03-16-11-06-27 ctime=2019-03-16-11-06-31
95 1846266 -rw-r--r-- 1 root www 3697930 54 "Mar 16 11:06:31 2019" "Mar 
16 11:06:27 2019" "Mar 16 11:06:31 2019" "Mar 16 11:06:27 2019" 32768 8 
0 experiment

4. change parmeter to file experiment
ls comand with last modification time and last access time
-rwxr-xr-x  1 root  www  54 Mar 16 11:06:27 2019 experiment
-rwxr-xr-x  1 root  www  54 Mar 16 11:06:31 2019 experiment
file=experiment size=54 atime=2019-03-16-11-06-31 
mtime=2019-03-16-11-06-27 ctime=2019-03-16-11-06-35
95 1846266 -rwxr-xr-x 1 root www 3697930 54 "Mar 16 11:06:31 2019" "Mar 
16 11:06:27 2019" "Mar 16 11:06:35 2019" "Mar 16 11:06:27 2019" 32768 8 
0 experiment

5. run file experiment
I am experiment in time
95 1846266 -rwxr-xr-x 1 root www 3697930 54 "Mar 16 11:06:39 2019" "Mar 
16 11:06:27 2019" "Mar 16 11:06:35 2019" "Mar 16 11:06:27 2019" 32768 8 
0 experiment
ls comand with last modification time and last access time
-rwxr-xr-x  1 root  www  54 Mar 16 11:06:27 2019 experiment
-rwxr-xr-x  1 root  www  54 Mar 16 11:06:39 2019 experiment
file=experiment size=54 atime=2019-03-16-11-06-39 
mtime=2019-03-16-11-06-27 ctime=2019-03-16-11-06-35
95 1846266 -rwxr-xr-x 1 root www 3697930 54 "Mar 16 11:06:39 2019" "Mar 
16 11:06:27 2019" "Mar 16 11:06:35 2019" "Mar 16 11:06:27 2019" 32768 8 
0 experiment
#

p.s. mozno niekomu usetrim trocha casu
Jozef



More information about the Users-l mailing list