Posted: . At: 10:16 AM. This was 2 years ago. Post ID: 15671
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Get information about your root filesystem on Linux very easily. This is very useful.


Get information about the creation date of your root filesystem on Linux

The Linux stat(1) utility will print information about your root filesystem. The Birth entry shows when the filesystem was created. This was the start of the Arch Linux installation procedure.

┌──[jason@11000000.10101000.00000001.00000011][~/Desktop]
└──╼  ╼ $ stat /
  File: /
  Size: 4096      	Blocks: 8          IO Block: 4096   directory
Device: 8,3	Inode: 2           Links: 17
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-11-28 17:24:59.677610100 +1100
Modify: 2021-11-26 22:13:50.072750646 +1100
Change: 2021-11-26 22:13:50.072750646 +1100
 Birth: 2021-11-26 22:04:40.000000000 +1100

Get just the birth date of the filesystem like this. This could be very useful if you wish to know when a certain partition was created.

┌──[jason@11000000.10101000.00000001.00000011][~/Desktop]
└──╼  ╼ $ stat / | grep "Birth" | sed 's/Birth: //g' | cut -b 2-11
2021-11-26

This version will show the entries and just the date and time.

┌──[jason@11000000.10101000.00000001.00000011][/mnt/windows/backups/homer]
└──╼  ╼ $ stat / | grep [A-Z] | sed 's/ Birth: /Birth:  /g' | cut -b 1-24
  File: /
  Size: 4096      	Block
Device: 8,3	Inode: 2
Access: (0755/drwxr-xr-x
Access: 2021-11-28 17:24
Modify: 2021-11-26 22:13
Change: 2021-11-26 22:13
Birth:  2021-11-26 22:04

So, a very useful command indeed.

This is another method. This will get the date and time the filesystem was created.

[root@darkstar homer]# tune2fs -l /dev/sda3  | grep 'Filesystem created:'
Filesystem created:       Fri Nov 26 22:04:40 2021

That is also a very useful command.

This is a way to find out which device the / partition is on.

[root@darkstar homer]# mount | grep "on / type"
/dev/sda3 on / type ext4 (rw,relatime)

Or even this way. Both work fine.

[root@darkstar homer]# dumpe2fs $(mount | grep 'on \/ ' | awk '{print $1}') | grep 'Filesystem created:'
dumpe2fs 1.46.4 (18-Aug-2021)
Filesystem created:       Fri Nov 26 22:04:40 2021

This is how to print the uptime of your Linux system in minutes. This is the value in seconds divided by 60.

┌──[jason@11000000.10101000.00000001.00000011][/mnt/windows/backups/homer]
└──╼  ╼ $ awk '{print int($1+0.5)/60}' /proc/uptime

The example below shows the rounded number of seconds the machine has been up.

┌──[jason@11000000.10101000.00000001.00000011][/mnt/windows/backups/homer]
└──╼  ╼ $ awk '{print int($1+0.5)}' /proc/uptime
12345

All in all, these are very useful tips. Could be useful in bash scripts.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.