Home > OS >  The time stamp
The time stamp

Time:12-29

How to use the Linux shell will file modification time differ with the current system time display how many seconds

CodePudding user response:

The shell can't do that, write a program yourself, using the stat function for file information

CodePudding user response:

 
#!/bin/bash

Time1=$(stat - t $1 | awk '} {print $12)
Time2=$(date + % s)

Echo ` expr $Time2 - $Time1 `

CodePudding user response:

refer to the second floor mouse_zhu response:
 
#!/bin/bash

Time1=$(stat - t $1 | awk '} {print $12)
Time2=$(date + % s)

Echo ` expr $Time2 - $Time1 `
to the specified file

CodePudding user response:

#!/bin/sh
Current_time=$(date + % s)
Echo the current time ${current_time}
File_time=$(stat - c % X test. The c)
Echo modification time ${file_time}

CodePudding user response:

Echo time ` expr $current_time - $file_time `

CodePudding user response:

$1 is the current time,./test. Sh file

CodePudding user response:

references moreover at 3/f response:
Quote: refer to the second floor mouse_zhu response:
 
#!/bin/bash

Time1=$(stat - t $1 | awk '} {print $12)
Time2=$(date + % s)

Echo ` expr $Time2 - $Time1 `
to the specified file

$1 is the name of the file,./test. Sh file
  • Related