Created
December 20, 2022 22:07
-
-
Save SubOptimal/6fe3f8e3b7400fcdbef66a5779c08b20 to your computer and use it in GitHub Desktop.
Linux file timestamps - birth, atime, mtime, ctime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
birth - created - touch | |
birth 2022-12-20 22:56:54.558640670 +0100 | |
access 2022-12-20 22:56:54.558640670 +0100 | |
modify 2022-12-20 22:56:54.558640670 +0100 | |
change 2022-12-20 22:56:54.558640670 +0100 | |
atime - accessed - cat | |
birth 2022-12-20 22:56:54.558640670 +0100 | |
access 2022-12-20 22:56:55.570654581 +0100 | |
modify 2022-12-20 22:56:54.558640670 +0100 | |
change 2022-12-20 22:56:54.558640670 +0100 | |
mtime - modified - added line | |
birth 2022-12-20 22:56:54.558640670 +0100 | |
access 2022-12-20 22:56:55.570654581 +0100 | |
modify 2022-12-20 22:56:56.578668421 +0100 | |
change 2022-12-20 22:56:56.578668421 +0100 | |
ctime - changed - chmod | |
birth 2022-12-20 22:56:54.558640670 +0100 | |
access 2022-12-20 22:56:55.570654581 +0100 | |
modify 2022-12-20 22:56:56.578668421 +0100 | |
change 2022-12-20 22:56:57.586682257 +0100 | |
times using ls | |
birth -rw-r--r-- 1 1000 1000 12 22:56:54.558640670 somefile | |
atime -rw-r--r-- 1 1000 1000 12 22:56:55.570654581 somefile | |
mtime -rw-r--r-- 1 1000 1000 12 22:56:56.578668421 somefile | |
ctime -rw-r--r-- 1 1000 1000 12 22:56:57.586682257 somefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# aim of the script is to show the different file timestamps and which action updates which one | |
stats() { | |
stat --printf "birth %w\naccess %x\nmodify %y\nchange %z\n" somefile | |
sleep 1 | |
} | |
rm -f somefile | |
# creation of the file | |
echo -e "\nbirth - created - touch" | |
touch somefile | |
stats | |
# access the content of the file | |
echo -e "\natime - accessed - cat" | |
cat somefile > /dev/null | |
stats | |
# modify the content of the file | |
echo -e "\nmtime - modified - added line" | |
echo "new content" >> somefile | |
stats | |
# change metadata of the file | |
echo -e "\nctime - changed - chmod" | |
chmod +w somefile | |
stats | |
echo -e "\ndisplay filetimes using ls" | |
printf "birth " | |
ls --time-style "+%H:%M:%S.%N" -ln --time=birth somefile | |
printf "atime " | |
ls --time-style "+%H:%M:%S.%N" -ln --time=atime somefile | |
printf "mtime " | |
ls --time-style "+%H:%M:%S.%N" -ln somefile | |
printf "ctime " | |
ls --time-style "+%H:%M:%S.%N" -ln --time=ctime somefile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment