Date Command

Embed Size (px)

DESCRIPTION

date command

Citation preview

[root@localhost ~]# dateSat Sep 6 07:31:37 EDT 2014[root@localhost ~]#[root@localhost ~]# hwclock --showSat 06 Sep 2014 07:35:12 AM EDT -0.625234 seconds[root@localhost ~]# dateSat Sep 6 07:33:29 EDT 2014[root@localhost ~]#Use the following syntax to set new data and time:------------------------------------------------- date --set="STRING"[root@localhost ~]# date --set="6 Sep 2014 07:38:18"Sat Sep 6 07:38:18 EDT 2014[root@localhost ~]# dateSat Sep 6 07:38:20 EDT 2014[root@localhost ~]# date +%y%m%d -s "07:41:31"140906[root@localhost ~]# dateSat Sep 6 07:41:33 EDT 2014[root@localhost ~]#date +"%Y-%m-%d"how to create a file with date and time------------------------------------------ %F full date; same as %Y-%m-%d %r locales 12-hour clock time (e.g., 11:11:04 PM) %R 24-hour hour and minute; same as %H:%M[root@localhost ~]# touch file1.$(date +%F_%r)[root@localhost ~]# ls -ltr file1.2014-09-06_07\:49\:17-rw-r--r-- 1 root root 0 Sep 6 07:49 file1.2014-09-06_07:49:17[root@localhost ~]#[root@localhost ~]# cp file3 file4.$(date +%F)[root@localhost ~]# ls -ltr file4.2014-09-06-rw-r--r-- 1 root root 0 Sep 6 07:52 file4.2014-09-06[root@localhost ~]#[root@localhost ~]# cp file3 file4.`date +%F`cp: overwrite `file4.2014-09-06'? y[root@localhost ~]# ls -ltr file4.2014-09-06-rw-r--r-- 1 root root 0 Sep 6 07:53 file4.2014-09-06[root@localhost ~]#[root@localhost test]# cp file file.`date +%F`.jpg[root@localhost test]# ls -ltr file.2014-09-06.jpg file-rw-r--r-- 1 root root 0 Sep 6 08:06 file-rw-r--r-- 1 root root 0 Sep 6 08:07 file.2014-09-06.jpg[root@localhost test]#[root@localhost test]# find . -name "*.gz" 2>/dev/null./file3.gz./file1.gz./file2.gz[root@localhost test]# find . -name "*.gz" 2>/dev/null |while read filename ;do cp $filename $filename.`date +%F` ;done[root@localhost test]# ls -ltr file*-rw-r--r-- 1 root root 0 Sep 6 08:06 file-rw-r--r-- 1 root root 0 Sep 6 08:07 file.2014-09-06.jpg-rw-r--r-- 1 root root 0 Sep 6 08:10 file1.gz-rw-r--r-- 1 root root 0 Sep 6 08:10 file2.gzx-rw-r--r-- 1 root root 0 Sep 6 08:10 file2.gz-rw-r--r-- 1 root root 0 Sep 6 08:10 file3.gz-rw-r--r-- 1 root root 0 Sep 6 08:13 file3.gz.2014-09-06-rw-r--r-- 1 root root 0 Sep 6 08:13 file1.gz.2014-09-06-rw-r--r-- 1 root root 0 Sep 6 08:13 file2.gz.2014-09-06[root@localhost test]#