한국어

네트워킹

온누리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
조회 수 :
103751
등록일 :
2013.07.11
10:31:00 (*.160.41.148)
엮인글 :
http://webs.co.kr/index.php?document_srl=21554&act=trackback&key=903
게시글 주소 :
http://webs.co.kr/index.php?document_srl=21554
List of Articles
번호 제목 글쓴이 날짜 조회 수sort
123 Tls ssl admin 2020-02-13 9756
122 DebianPackageManagement admin 2019-04-08 12063
121 데비안 제시 jessie 소스리스트 sourcelist admin 2019-06-17 13727
120 debian Ubuntu 에서 Timezone 확인 및 변경하기 쉽게 간단하게 date time admin 2019-11-09 14424
119 Redis 소개와 설치 방법, 보안 설정 방법(ip 허용, 비밀번호 설정)등 빠르게 세팅하기 admin 2020-01-10 14746
118 vi 에디터에서 ^M 문자 한번에 모두 지우기 ( ^M, ^L을 이해하자) admin 2019-06-20 14885
117 Debian vs Ubuntu: Compared as a Desktop and as a Server 데비안 vs 우분투 비교 admin 2019-10-31 15813
116 리눅스 우분투, 32비트 64비트 확인 명령어 admin 2019-01-06 16572
115 Start Stop Restart Apache 2 Web Server Command Debian Ubuntu CentOS RHEL Fedora admin 2018-04-14 17804
114 File Descriptor (파일 디스크립터) 설명 무엇인가 사용방법 admin 2019-06-01 18297
113 리눅스 서버 유지보수 점검 메인터넌스 상황 파악 admin 2018-04-14 18368
112 고정ip설정, dns설정(데비안) linux 리눅스 admin 2018-06-13 19354
111 리눅스 한글 2014 뷰어 다운로드 - hwpviewer admin 2018-03-28 19491
110 리눅스를 백업 복구 tar admin 2018-03-28 21671
109 linux debian 계열 network 설정 테트워크 데비안 admin 2017-09-07 21978
108 What's the difference between “adduser” and “useradd”? admin 2017-12-15 22187
107 데비안 리눅스 부팅시에 방화벽 서버에 자동실행 되게 설정 해보자 admin 2017-08-30 22362
106 Error : unary operator expected – 쉘스크립트 타입관련 문법 admin 2019-09-14 22870
105 openssl 을 이용한 인증서 생성 절차를 정리한다. 개인키 CSR SSL 인증서 파일 생성 admin 2017-09-14 23111
104 Top 20 OpenSSH Server Best Security Practices 보안 대책 실제 적용 admin 2018-04-14 23325
103 Lnux export how to admin 2017-12-17 23470
102 find 명령 사용 예제들 admin 2014-10-29 24231
101 SSH 무작위 로그인 시도 막기(With Fail2Ban on CentOS 6/7 + selinux) admin 2017-09-12 24251
100 sources.list lenny admin 2015-02-03 24264
99 Download all files in a directory using WGET admin 2014-12-16 24624
98 mount -t auto /dev/sdb1 /mnt && ls /mnt admin 2015-06-27 25450
97 우분투 Linux(Ubuntu)에 Java설치 및 환경 설정하는 방법 admin 2017-10-13 25452
96 데비안 vs 우분투 : 데스크탑과 서버로 비교 해외 글 과 댓글 admin 2019-10-31 25903
95 우분투 다운로드 사이트 주소 ubuntu download 16.04.3 17.04 site link admin 2017-10-13 26094
94 Install Missing ifconfig Command on Debian ip address admin 2019-11-05 26351