10 Examples Of Appointment Ascendance Inward Linux Too Unix

Date dominance inwards unix or Linux is ane of of import dominance to acquire in addition to principal because nosotros e'er involve appointment information. no thing you lot desire to know current appointment inwards unix or your bash script needs electrical flow appointment inwards unix for archiving role you lot involve to utilization appointment command. In its simplest format appointment dominance shows the current appointment in addition to time inwards unix piece amongst sophisticated choice nosotros tin extract many useful information from unix appointment command. In this Unix dominance tutorial  we volition meet some useful tips on using date dominance inwards unix in addition to acquire to a greater extent than around appointment inwards unix in addition to Linux. One of import thing to complaint is that dissimilar implementation of unix appointment dominance may non live on just same e.g. AIX version of appointment dominance doesn't back upwards choice "-d" or "date". Anyway let's meet some instance of unix appointment command:

By the means this is 5th article inwards my serial of roofing examples of of import in addition to oft used commands e.g. find examples, grep examples, chmod example in addition to sort dominance example.


1) Example 1 -  displaying electrical flow appointment in addition to fourth dimension inwards Unix
This is simplest utilization of unix appointment command. only type appointment inwards the dominance prompt in addition to it volition present you lot the electrical flow appointment in addition to fourth dimension inwards the timezone your machine is.

/java date
Thu Jul 14 14:31:35 MPST 2011



2) Example 2 - displaying Julian appointment inwards Unix
 or Linux is ane of of import dominance to acquire in addition to principal because nosotros e'er involve appointment information 10 Examples of Date Command inwards Linux in addition to UNIXmost of coffee stock trading application running nether Linux utilization Julian appointment format to shop appointment information. Julian dates are made of v digits 2 of which correspond twelvemonth in addition to iii or final digit correspond twenty-four hr menses of year. for instance 14th July 20111 volition live on represented yesteryear 11195 inwards Julian format because 14th July is the 195th twenty-four hr menses of the year. nosotros tin acquire Julian appointment yesteryear using appointment dominance inwards unix every bit shown inwards the below instance of unix appointment command:

Converting electrical flow date into Julian format in unix
/java date +%j
195

Converting a specific date into Julian format in unix
/java date -d "2011/07/13" +%j
194

this means you lot tin acquire yesterdays Julian appointment or tomorrow's Julian appointment inwards Unix though I receive got heard that "-d" choice of appointment is non supported inwards AIX in addition to thus this may non run inwards AIX version of Unix.


3) Example iii - displaying electrical flow appointment inwards diverse format inwards unix
Unix appointment dominance is really powerful in addition to tin present appointment inwards diverse format. inwards this department of unix appointment tutorial nosotros volition convert appointment into some usually used appointment format inwards unix:

Showing date in YYYYMMDD format in Unix
/java date +%Y%m%d
20110714

here %Y shows twelvemonth inwards 4 digit ( you lot tin utilization %y (small letter) for displaying only 2 digit of year)  %m  shows 2 digit of calendar month every bit 01..12 in addition to %d correspond twenty-four hr menses of month.

Showing date in DD/MM/YYYY format in unix
/java date +%d\/%m\/%Y
14/07/2011

here in ane lawsuit to a greater extent than %d is for twenty-four hr menses %m is for calendar month in addition to %Y is for 4 digit twelvemonth if you lot desire to present 2 digit utilization small-scale instance y e.g. %y

Showing date in DD-MM-YY format in unix
/java date +%d\-%m\-%Y
14-07-2011

quite like to inwards a higher house approach only chaged the "/" to "-", you lot tin alter it to whatever graphic symbol every bit per your wishing in addition to until unix receive got it.


displaying appointment inwards MM/DD/YYYY format inwards Unix
what create you lot guys mean value would it live on hard no correct ? only telephone substitution house of "%m" in addition to "%d" in addition to you lot are laid every bit shown inwards below instance of appointment dominance inwards unix

/java date +%m\/%d\/%Y
07/14/2011

displaying appointment inwards YYYY-MM-DD format is just like to inwards a higher house approach only alter the guild of twelvemonth in addition to month.


4) How to uncovering appointment seven days earlier electrical flow appointment inwards Unix
This is actually prissy of gnu version of unix appointment command you lot tin easily acquire what's the appointment 4 days earlier or v days earlier yesteryear using appointment dominance inwards unix. hither is example:

date later on 7 days in unix
/java date -d "-7 days"
Thu Jul  7 14:54:36 MPST 2011

by using this means you lot tin uncovering whatever appointment which is whatever days apart from a given electrical flow appointment inwards unix


5) How to acquire appointment seven days later on electrical flow twenty-four hr menses inwards Unix in addition to Linux
As shown inwards a higher house you lot tin acquire the appointment later on seven days inwards unix yesteryear using gnu version of appointment dominance inwards unix, hither is an instance of getting appointment seven days later on electrical flow date:

/java date -d "7 days"
Thu Jul 21 14:54:15 MPST 2011

this means you lot tin uncovering whatever appointment which is seven days yesteryear of a given electrical flow appointment inwards unix


6) Setting appointment fourth dimension into unix
setting appointment is tardily though I don't recommend to create it if you lot receive got unix admins. Also changing appointment requires rootage access which you lot mightiness non receive got amongst you lot anyway nosotros tin utilization unix appointment dominance to alter the date, only render novel appointment inwards the specified format in addition to your electrical flow appointment volition live on laid to novel date.

format of setting appointment fourth dimension into unix

date mmddhhmi

where mm = month
      dd = twenty-four hr menses of month
      hh = hour
      mi = minute
  
Example of changing appointment fourth dimension inwards unix

/java date 07240222
Sunday Jul 24 02:22:00 MPST 2011

above example of appointment command volition laid the electrical flow appointment to 24th July in addition to fourth dimension to 02:22, nosotros don't render twelvemonth information in addition to appointment uses electrical flow twelvemonth yesteryear default.

7) How to uncovering timezone yesteryear using unix appointment dominance - Example
unix appointment dominance tin display timezone related information also. it provides next choice to display timezone
  %:z  +hh:mm numeric fourth dimension zone (e.g., -04:00)
  %::z  +hh:mm:ss numeric fourth dimension zone (e.g., -04:00:00)
  %:::z  numeric fourth dimension zone amongst : to necessary precision (e.g., -04, +05:30)
  %Z   alphabetic fourth dimension zone abbreviation (e.g., EDT)

Now let's meet some instance of unix appointment dominance to display timezone

/java date +%Z  (this volition display timezone in mutual format e.g. EST, GMT)
MPST

/java date +%z  (this choice of unix date command volition display timezone respective of GMT)
+0800


8) How to present twenty-four hr menses of calendar week inwards Unix using appointment dominance - Exmaple
you tin present electrical flow date, twenty-four hr menses of calendar week scream using unix appointment command  yesteryear using options "%a" in addition to "%A". small-scale instance is used to display twenty-four hr menses inwards brusk format piece upper-case missive of the alphabet ane is used to display total scream of day. meet the below instance of appointment dominance inwards unix for display twenty-four hr menses of calendar week :

/java date +%a
Thu

/java date +%A
Thursday


9) Date dominance inwards Unix for showing electrical flow fourth dimension inwards Various format
time is some other of import information which nosotros tin acquire from unix appointment command. yesteryear default appointment dominance inwards unix display both appointment in addition to fourth dimension information but nosotros tin utilization diverse options provided yesteryear appointment dominance to display solely fourth dimension information. let's meet some instance of showing fourth dimension using unix appointment command:

10) Date to dominance for showing fourth dimension inwards format HH:MM:SS
As shown inwards a higher house on showing appointment inwards dissimilar format inwards unix you lot tin every bit good display fourth dimension on dissimilar format yesteryear applying same approach. you lot only involve to recollect next fourth dimension related options of unix appointment command

%H   hr (00..23)
%M   infinitesimal (00..59)
%S   2nd (00..60)

that's all for at in ane lawsuit guys I promise you lot volition live on to a greater extent than comfortable amongst appointment dominance inwards unix later on going through in addition to trying these examples. you lot tin acquire to a greater extent than information close appointment dominance inwards unix yesteryear using "man date" or "date --help" which volition every bit good listing all the options supported yesteryear unix appointment command.

Tip: only recollect that unix appointment command is by in addition to large used within bash script to acquire the appointment information , in addition to thus its worth mentioning hither how to execute appointment dominance from bash script, you lot only involve to specify appointment dominance inwards dorsum quotes . meet the instance bash script  :

/java cat unixdate.sh
#!/bin/bash

DATE=`date`
echo "Current date: $DATE"

/java ./unixdate.sh
Current date: Sunday Jul 24 02:30:50 MPST 2011

So that was all close dissimilar examples of appointment command. We receive got seen how nosotros tin format appointment inwards Unix, how nosotros tin convert appointment into dissimilar timezone inwards Unix, how nosotros tin acquire electrical flow appointment in addition to fourth dimension within bash script in addition to several other examples of appointment command. Let me know if you lot receive got whatever other usage of appointment dominance which is non covered here.

Further Learning
Linux Command Line Basics
How to uncovering IP address from hostname inwards Linux

Belum ada Komentar untuk "10 Examples Of Appointment Ascendance Inward Linux Too Unix"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel