5

How to create date type in bash?

what this date mean? '1803141400'

touch -t 1803141400 test1 test2

How can I compute time?

2 Answers 2

6

According to touch man page:

  -t STAMP
              use [[CC]YY]MMDDhhmm[.ss] instead of current time

where:

CC: First two digit of the year
YY: Last two digits of the year
MM: Month (two-digit numeric month)
DD: Day (two-digit numeric day i.e. day of month)
hh: Hour
mm: Minutes
ss: Seconds

[] indicates that field is optional

In your examples 1803141400 means: 2018 mar 14, 14.00 and touch will change time stamp of test1 and test2 files according to this value.

$ ls -l test1 test2
-rw-rw-r-- 1 yourUser yourGroup 0 mar 14  2018 test1
-rw-rw-r-- 1 yourUser yourGroup 0 mar 14  2018 test2
0

The -t options allow the user to add a specific last access time when you create a file using touch command .

It is followed by a string in the date, month, year, minute:second format, and the latter uses a [[CC]YY]MMDDhhmm[.ss] format, where CC,YY and SS is optional.

For example, to create file temp with time stamp

 [guru@guru-Aspire ~]$touch -t 12141105  temp
 [guru@guru-Aspire ~]$ls -l --full-time temp

  -rw-rw-r-- 1 guru guru 0 2014-12-14 11:05:00.000000000 +0530 temp

As you ca see if you do not provide CC and YY, it automatically insert the current CC and YY.

In your case i.e. touch -t 1803141400 test1 test2

it will create a timstamp of

year- 2018 (first pair of digit)

month- 03 (second pair of digit)

date- 14 (third pair of digit)

time - 14:02 (fourth and fifth pair of digit)

[guru@guru-Aspire ~]$ ls -l --full-time test*
-rw-rw-r-- 1 guru guru 0 2018-03-14 14:00:00.000000000 +0530 test1
-rw-rw-r-- 1 guru guru 0 2018-03-14 14:00:00.000000000 +0530 test2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .