한국어

네트워킹

온누리070 플레이스토어 다운로드
    acrobits softphone
     온누리 070 카카오 프러스 친구추가온누리 070 카카오 프러스 친구추가친추
     카카오톡 채팅 상담 카카오톡 채팅 상담카톡
    
     라인상담
     라인으로 공유

     페북공유

   ◎위챗 : speedseoul


  
     PAYPAL
     
     PRICE
     

pixel.gif

    before pay call 0088 from app


https://library.linode.com/linux-tools/common-commands/date

Date command is helpful to display date in several formats. It also allows you to set systems date and time.

This article explains few examples on how to use date command with practical examples.

When you execute date command without any option, it will display the current date and time as shown below.

$ date
Mon May 20 22:02:24 PDT 2013

1. Display Date from a String Value using –date Option

If you have a static date or time value in a string, you can use -d or –date option to convert the input string into date format as shown below.

Please note that this doesn’t use the current date and time value. Instead is uses the date and time value that you pass as string.

The following examples takes an input date only string, and displays the output in date format. If you don’t specify time, it uses 00:00:00 for time.

$ date --date="12/2/2014"
Tue Dec  2 00:00:00 PST 2014

$ date --date="2 Feb 2014"
Sun Feb  2 00:00:00 PST 2014

$ date --date="Feb 2 2014"
Sun Feb  2 00:00:00 PST 2014

The following example takes an input date and time string, and displays the output in date format.

$ date --date="Feb 2 2014 13:12:10"
Sun Feb  2 13:12:10 PST 2014

2. Read Date Patterns from a file using –file option

This is similar to the -d or –date option that we discussed above. But, you can do it for multiple date strings. If you have a file that contains various static date strings, you can use -f or –file option as shown below.


In this example, we can see that datefile contained 2 date strings. Each line of datefile is parsed by date command and date is outputted for each line.

$ cat datefile
Sept 9 1986
Aug 23 1987

$ date --file=datefile
Tue Sep  9 00:00:00 PDT 1986
Sun Aug 23 00:00:00 PDT 1987

3. Get Relative Date Using –date option

You can also use date command to get a future date using relative values.

For example, the following examples gets date of next Monday.

$ date --date="next mon"
Mon May 27 00:00:00 PDT 2013

If string=@is given to date command, then date command convert seconds since the epoch (1970-01-01 UTC) to a date.

It displays date in which 5 seconds are elapsed since epoch 1970-01-01 UTC:

$ date --date=@5
Wed Dec 31 16:00:05 PST 1969

It displays date in which 10 seconds are elapsed since epoch 1970-01-01 UTC:

$ date --date=@10
Wed Dec 31 16:00:10 PST 1969

It displays date in which 1 minute (i.e. 60 seconds) is elapsed since epoch 1970-01-01 UTC:

$ date --date=@60
Wed Dec 31 16:01:00 PST 1969

4. Display Past Date

You can display a past date using the -date command. Few possibilities are shown below.

$ date --date='3 seconds ago'
Mon May 20 21:59:20 PDT 2013

$ date --date="1 day ago"
Sun May 19 21:59:36 PDT 2013

$ date --date="yesterday"
Sun May 19 22:00:26 PDT 2013

$ date --date="1 month ago"
Sat Apr 20 21:59:58 PDT 2013

$ date --date="1 year ago"
Sun May 20 22:00:09 PDT 2012

5. Set Date and Time using –set option

You can set date and time of your system using -s or –set option as shown below..

In this example, initially it displayed the time as 20:09:31. We then used date command to change it to 21:00:00.

$ date
Sun May 20 20:09:31 PDT 2013

$ date -s "Sun May 20 21:00:00 PDT 2013"
Sun May 20 21:00:00 PDT 2013

$ date
Sun May 20 21:00:05 PDT 2013

5. Display Universal Time using -u option

You can display date in UTC format using -u, or –utc, or –universal option as shown below.

$ date
Mon May 20 22:07:53 PDT 2013

$ date -u
Tue May 21 05:07:55 UTC 2013

6. Display Last Modification Time using -r option

In this example, the current time is 20:25:48

$ date
Sun May 20 20:25:48 PDT 2013

The timestamp of datefile is changed using touch command. This was done few seconds after the above date command’s output.

$ touch datefile

The current time after the above touch command is 20:26:12

$ date
Sun May 20 20:26:12 PDT 2013

Finally, use the date command -r option to display the last modified timestamp of a file as shown below. In this example, it displays last modified time of datefile as 20:25:57. It is somewhere between 20:25:48 and 20:26:12 (which is when we execute the above touch command to modify the timestamp).

$ date -r datefile
Sun May 20 20:25:57 PDT 2013

7. Various Date Command Formats

You can use formatting option to display date command in various formats using the following syntax:

$ date +%<format-option>

The following table displays various date command formatting options.

Format optionsPurpose of OptionOutput
date +%aDisplays Weekday name in short (like Mon, Tue, Wed)Thu
date +%ADisplays Weekday name in full short (like Monday, Tuesday)Thursday
date +%bDisplays Month name in short (like Jan, Feb, Mar )Feb
date +%BDisplays Month name in full short (like January, February)February
date +%dDisplays Day of month (e.g., 01)07
date +%DDisplays Current Date; shown in MM/DD/YY02/07/13
date +%FDisplays Date; shown in YYYY-MM-DD2013-02-07
date +%HDisplays hour in (00..23) format23
date +%IDisplays hour (01..12) format11
date +%jDisplays day of year (001..366)038
date +%mDisplays month (01..12)02
date +%MDisplays minute (00..59)44
date +%SDisplays second (00..60)17
date +%NDisplays nanoseconds (000000000..999999999)573587606
date +%TDisplays time; shown as HH:MM:SS
Note: Hours in 24 Format
23:44:17
date +%uDisplays day of week (1..7); 1 is Monday4
date +%UDisplays week number of year, with Sunday as first day of week (00..53)05
date +%YDisplays full year i.e. YYYY2013
date +%Zalphabetic time zone abbreviation (e.g., EDT)IS
조회 수 :
103947
등록일 :
2013.07.11
10:31:00 (*.160.41.148)
엮인글 :
http://www.webs.co.kr/index.php?document_srl=21554&act=trackback&key=6e6
게시글 주소 :
http://www.webs.co.kr/index.php?document_srl=21554
List of Articles
번호 제목 글쓴이 조회 수sort 추천 수 날짜
63 ftp 파일전송 여러파일을 한번에 통째로 전송 admin 37697   2011-12-16
 
62 스트리밍서버 / 윈도우서버 admin 37593   2011-12-16
 
61 Deploying FreeRADIUS with the MySQL Cluster Database file admin 37109   2013-03-22
 
60 리눅스 tar 압축 백업복원시 소유자 문제해결 admin 37108   2011-12-16
 
59 Start / Stop and Restart Apache 2 Web Server Command 아파치 시작 스톱 명령어 admin 37033   2019-04-08
 
58 How to start GUI from command line? admin 36900   2014-12-21
 
57 리눅스 시작시 부팅 시, 프로그램 자동실행 등록하기 admin 36590   2017-08-30
 
56 WinXP 부팅안되는 현상 NTLDR is missing 메세지 admin 36370   2012-07-12
 
55 Cloned VMware CentOS6 Server "device eth0 does not seem to be present, admin 36101   2017-08-29
 
54 Using Windows RDP to Access your Ubuntu Instance admin 34961   2014-12-21
 
53 문서 편집기 vi vim command 명령어 정리 admin 34186   2014-10-29
 
52 검색 파일리스트 만든 다음 여러파일 한방에 압축하기 admin 33041   2012-02-14
 
51 Linux Memory Management – Virtual Memory and Demand Paging admin 32919   2014-03-03
 
50 [리눅스] 부팅 시 자동 실행 프로그램 등록|작성자 나눔HN admin 32746   2018-06-01
 
49 리눅스 시스템 유저 추가 명령어 useradd 사용하기 admin 32453   2014-08-09
 
48 윈도우 ssh 접속 프로그램 admin 31573   2017-09-29
 
47 리눅스의 막강한 네트워크 필터 iptables admin 31543   2012-04-15
 
46 Remote Desktop Connection from Windows 7/8 to Ubuntu 14.04 admin 31458   2014-12-21
 
45 Name Server 설정및 이해 admin 31424   2011-12-13
 
44 [리눅스] 소프트웨어 레이드의 리빌딩 및 리싱킹 속도를 높이는 5가지 방법 admin 31021   2014-10-17
 
43 debian 8.8 download cd1 cd2 cd3 etc admin 30797   2017-09-03
 
42 VMWARE VM Error boot loader install grub - install /dev/sda or /dev/hda MBR linux admin 30717   2016-01-27
 
41 Install GUI on Ubuntu Server admin 30490   2014-12-21
 
40 무료백신 여러가지 분류해놓은곳 admin 30463   2011-12-16
 
39 Event IP 20187 admin 30453   2013-04-08
 
38 zip 압축 파일 및 텍스트 파일의 한글 깨짐 해결 방법 admin 30244   2018-03-28
 
37 Wireshark admin 30166   2011-12-16
 
36 다양한 사운드 파일있는곳 admin 30026   2011-12-19
 
35 Linux and Unix touch command admin 28847   2015-11-15
 
34 /bin/false, /sbin/nologin 의 차이점 admin 28533   2014-10-13