FilesystemTimestamp
Lizenz: Dieser Artikel wurde als problematisch in Bezug auf der Lizenz markiert, dafür kann es verschiedene Gründe geben:
Bitte hilf mit alle diese Fragen zunächst zu klären, danach kann dieser Hinweis entfernt werden. |
Scripting / Scripting Dateisystem / FilesystemTimestamp
Auflistung welcher Zeitstempel von einem Dateisystemen bei verschiedenen Dateiaktion gesetzt wird
Auf der Debian Mailingliste debian-user-german gab es gerade (15.12.) eine interessante Diskussion um die Zeitstempel (access, modification und change time) im Dateisystem. Er war zu sehen, dass die unterschiedlichen Zeitstempel nicht von allen Dateisystemen in gleicher Weise gesetzt werden.
Eine schnelle Übersicht, welchen Zeitstempel ein Dateisystem, bei bestimmten Aktionen setzt, liefert das folgende Skript.
Vor dem ersten Start müssen die Pfade zu den verschiedenen Dateisysteme noch angepasst werden. Welche Dateisysteme auf dem Rechner verwendet werden lässt sich so ganz schnell herausfinden.
user@debian:~$ df -hT
Aufruf
user@debian:~$ ./timestamps.sh
Damit es zu unterschiedlichen Zeitstempeln kommt, wurden in das Skript Pausen von je 1 Sekunde eingebaut. Die Ausgabe dauert insgesamt: (Anzahl Dateisysteme * 7) Sekunden.
# author: SubOptimal 16-Dec-2007
#
# Jabber ID: SubOptimal@debianforum.de
# define path to different filesystems, trailing slash is mandatory
# you need write access to this directories
path=( "/" "/dev/" "/home/" "/var/" "/tmp/" )
# get count of elements in path[]
path_cnt=${#path[@]}
# basename for dummy file
dummy_file=`mktemp -t SubOptimal.XXXXXXX`
dummy_file=${dummy_file##*/}
# to get different timestamps we need a short delay
delay() {
sleep 1
}
# gather filesystem type
get_fs_type () {
fs_type[$1]=`df -hT $2 | awk '/\// {print $2}'`
}
# create dummy file
create_dummy() {
touch ${1}${dummy_file}
}
# show filesystem times
show_times() {
printf "%-13s%-20s%-20s%-20s\n" "filesystem" "access time" "modification time" "change time"
for ((i=0;i<${path_cnt};i++))
do
printf "%-13s%-20s%-20s%-20s\n" ${fs_type[$i]} `stat -c "%x %y %z" ${path[$i]}${dummy_file} | cut -d " " -f 2,5,8`
done
}
# create file
printf "\ncreate files (touch filename)\n"
for ((i=0;i<${path_cnt};i++))
do
create_dummy ${path[$i]}
get_fs_type $i ${path[$i]}
delay
done
show_times
# modify files
printf "\nmodify files (echo \"foo\" > filename)\n"
for ((i=0;i<${path_cnt};i++))
do
echo "foo" > ${path[$i]}${dummy_file}
delay
done
show_times
# access files
printf "\naccess files (cat filename > /dev/null)\n"
for ((i=0;i<${path_cnt};i++))
do
cat ${path[$i]}${dummy_file} > /dev/null
delay
done
show_times
# change files
printf "\nchange files (mv filename filename_dest)\n"
for ((i=0;i<${path_cnt};i++))
do
mv ${path[$i]}${dummy_file} ${path[$i]}${dummy_file}_tmp
mv ${path[$i]}${dummy_file}_tmp ${path[$i]}${dummy_file}
delay
done
show_times
# change access time
printf "\ntouch access time on files (touch -a filename)\n"
for ((i=0;i<${path_cnt};i++))
do
touch -a ${path[$i]}${dummy_file}
delay
done
show_times
# change modification time
printf "\ntouch modification time on files (touch -m filename)\n"
for ((i=0;i<${path_cnt};i++))
do
touch -m ${path[$i]}${dummy_file}
delay
done
show_times
# touch access and modification time on files
printf "\ntouch access and modification time on files (touch filename)\n"
for ((i=0;i<${path_cnt};i++))
do
touch ${path[$i]}${dummy_file}
delay
done
show_times
# delete dummy files
for ((i=0;i<${path_cnt};i++))
do
rm ${path[$i]}${dummy_file}
done
Die Ausgabe sieht dann (abhängig von den Dateisystemen) z.B. so aus.
create files (touch filename) filesystem access time modification time change time ext3 13:47:20.000000000 13:47:20.000000000 13:47:20.000000000 tmpfs 13:47:21.000000000 13:47:21.000000000 13:47:21.000000000 xfs 13:47:22.867432136 13:47:22.867432136 13:47:22.867432136 ext2 13:47:23.000000000 13:47:23.000000000 13:47:23.000000000 jfs 13:47:24.963113544 13:47:24.963113544 13:47:24.963113544 modify files (echo "foo" > filename) filesystem access time modification time change time ext3 13:47:20.000000000 13:47:26.000000000 13:47:26.000000000 tmpfs 13:47:21.000000000 13:47:27.123785072 13:47:27.123785072 xfs 13:47:22.867432136 13:47:28.124632920 13:47:28.124632920 ext2 13:47:23.000000000 13:47:29.000000000 13:47:29.000000000 jfs 13:47:24.963113544 13:47:30.126328616 13:47:30.126328616 access files (cat filename > /dev/null) filesystem access time modification time change time ext3 13:47:31.000000000 13:47:26.000000000 13:47:26.000000000 tmpfs 13:47:32.000000000 13:47:27.123785072 13:47:27.123785072 xfs 13:47:22.867432136 13:47:28.124632920 13:47:28.124632920 ext2 13:47:23.000000000 13:47:29.000000000 13:47:29.000000000 jfs 13:47:35.153564360 13:47:30.126328616 13:47:30.126328616 change files (mv filename filename_dest) filesystem access time modification time change time ext3 13:47:31.000000000 13:47:26.000000000 13:47:36.000000000 tmpfs 13:47:32.000000000 13:47:27.123785072 13:47:37.257244552 xfs 13:47:22.867432136 13:47:28.124632920 13:47:38.274089968 ext2 13:47:23.000000000 13:47:29.000000000 13:47:39.000000000 jfs 13:47:35.153564360 13:47:30.126328616 13:47:40.284784296 touch access time on files (touch -a filename) filesystem access time modification time change time ext3 13:47:41.000000000 13:47:26.000000000 13:47:41.000000000 tmpfs 13:47:42.000000000 13:47:27.000000000 13:47:42.000000000 xfs 13:47:43.318121000 13:47:28.124632000 13:47:43.316323432 ext2 13:47:44.000000000 13:47:29.000000000 13:47:44.000000000 jfs 13:47:45.323820000 13:47:30.126328000 13:47:45.322018520 touch modification time on files (touch -m filename) filesystem access time modification time change time ext3 13:47:41.000000000 13:47:46.000000000 13:47:46.000000000 tmpfs 13:47:42.000000000 13:47:47.000000000 13:47:47.000000000 xfs 13:47:43.318121000 13:47:48.359364000 13:47:48.357557048 ext2 13:47:44.000000000 13:47:49.000000000 13:47:49.000000000 jfs 13:47:45.323820000 13:47:50.365027000 13:47:50.363252136 touch access and modification time on files (touch filename) filesystem access time modification time change time ext3 13:47:51.000000000 13:47:51.000000000 13:47:51.000000000 tmpfs 13:47:52.000000000 13:47:52.000000000 13:47:52.000000000 xfs 13:47:53.394791272 13:47:53.394791272 13:47:53.394791272 ext2 13:47:54.000000000 13:47:54.000000000 13:47:54.000000000 jfs 13:47:55.400486360 13:47:55.400486360 13:47:55.400486360
Don't trust the timestamp (to much). ;-)
Scripting / Scripting Dateisystem / FilesystemTimestamp