10 Examples Of Appointment Dominance Inwards Linux As Well As Unix

Date ascendence inwards unix or Linux is 1 of of import ascendence to acquire as well as primary because nosotros ever involve appointment information. no affair 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 ascendence shows the current appointment as well as time inwards unix spell amongst sophisticated selection nosotros tin dismiss extract many useful information from unix appointment command. In this Unix ascendence tutorial  we volition meet some useful tips on using date ascendence inwards unix as well as acquire to a greater extent than approximately appointment inwards unix as well as Linux. One of import thing to regime annotation is that dissimilar implementation of unix appointment ascendence may non hold upward precisely same e.g. AIX version of appointment ascendence doesn't back upward selection "-d" or "date". Anyway let's meet some illustration of unix appointment command:

By the means this is 5th article inwards my serial of roofing examples of of import as well as oftentimes used commands e.g. find examples, grep examples, chmod example as well as sort ascendence example.


1) Example 1 -  displaying electrical flow appointment as well as fourth dimension inwards Unix
This is simplest utilization of unix appointment command. simply type appointment inwards the ascendence prompt as well as it volition present you lot the electrical flow appointment as well as 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 1 of of import ascendence to acquire as well as primary because nosotros ever involve appointment information 10 Examples of Date Command inwards Linux as well as UNIXmost of coffee stock trading application running nether Linux utilization Julian appointment format to shop appointment information. Julian dates are made of five digits 2 of which stand upward for twelvemonth as well as three or concluding digit stand upward for twenty-four lx minutes menstruation of year. for illustration 14th July 20111 volition hold upward represented yesteryear 11195 inwards Julian format because 14th July is the 195th twenty-four lx minutes menstruation of the year. nosotros tin dismiss acquire Julian appointment yesteryear using appointment ascendence inwards unix every bit shown inwards the below illustration 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 dismiss acquire yesterdays Julian appointment or tomorrow's Julian appointment inwards Unix though I receive got heard that "-d" selection of appointment is non supported inwards AIX then this may non travel inwards AIX version of Unix.


3) Example three - displaying electrical flow appointment inwards diverse format inwards unix
Unix appointment ascendence is real powerful as well as tin dismiss present appointment inwards diverse format. inwards this department of unix appointment tutorial nosotros volition convert appointment into some ordinarily used appointment format inwards unix:

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

here %Y shows twelvemonth inwards iv digit ( you lot tin dismiss utilization %y (small letter) for displaying simply 2 digit of year)  %m  shows 2 digit of calendar month every bit 01..12 as well as %d stand upward for twenty-four lx minutes menstruation of month.

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

here 1 time to a greater extent than %d is for twenty-four lx minutes menstruation %m is for calendar month as well as %Y is for iv digit twelvemonth if you lot desire to present 2 digit utilization pocket-size 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 to a higher house approach simply chaged the "/" to "-", you lot tin dismiss modify it to whatever grapheme every bit per your wishing as well as until unix bring it.


displaying appointment inwards MM/DD/YYYY format inwards Unix
what create you lot guys intend would it hold upward hard no correct ? simply telephone commutation house of "%m" as well as "%d" as well as you lot are cook every bit shown inwards below illustration of appointment ascendence inwards unix

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

displaying appointment inwards YYYY-MM-DD format is precisely like to to a higher house approach simply modify the lodge of twelvemonth as well as month.


4) How to uncovering appointment seven days earlier electrical flow appointment inwards Unix
This is actually dainty of gnu version of unix appointment command you lot tin dismiss easily acquire what's the appointment 4 days earlier or five days earlier yesteryear using appointment ascendence 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 dismiss 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 lx minutes menstruation inwards Unix as well as Linux
As shown to a higher house you lot tin dismiss acquire the appointment later on seven days inwards unix yesteryear using gnu version of appointment ascendence inwards unix, hither is an illustration 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 dismiss 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 slowly though I don't recommend to create it if you lot receive got unix admins. Also changing appointment requires origin access which you lot mightiness non receive got amongst you lot anyway nosotros tin dismiss utilization unix appointment ascendence to modify the date, simply render novel appointment inwards the specified format as well as your electrical flow appointment volition hold upward laid upward to novel date.

format of setting appointment fourth dimension into unix

date mmddhhmi

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

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

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

7) How to uncovering timezone yesteryear using unix appointment ascendence - Example
unix appointment ascendence tin dismiss display timezone related information also. it provides next selection 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 illustration of unix appointment ascendence to display timezone

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

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


8) How to present twenty-four lx minutes menstruation of calendar week inwards Unix using appointment ascendence - Exmaple
you tin dismiss present electrical flow date, twenty-four lx minutes menstruation of calendar week holler using unix appointment command  yesteryear using options "%a" as well as "%A". pocket-size instance is used to display twenty-four lx minutes menstruation inwards brusque format spell uppercase 1 is used to display total holler of day. meet the below illustration of appointment ascendence inwards unix for display twenty-four lx minutes menstruation of calendar week :

/java date +%a
Thu

/java date +%A
Thursday


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

10) Date to ascendence for showing fourth dimension inwards format HH:MM:SS
As shown to a higher house on showing appointment inwards dissimilar format inwards unix you lot tin dismiss too display fourth dimension on dissimilar format yesteryear applying same approach. you lot simply involve to recall next fourth dimension related options of unix appointment command

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

that's all for straight off guys I promise you lot volition hold upward to a greater extent than comfortable amongst appointment ascendence inwards unix later on going through as well as trying these examples. you lot tin dismiss acquire to a greater extent than information most appointment ascendence inwards unix yesteryear using "man date" or "date --help" which volition too listing all the options supported yesteryear unix appointment command.

Tip: simply recall that unix appointment command is by as well as large used within bash script to acquire the appointment information , then its worth mentioning hither how to execute appointment ascendence from bash script, you lot simply involve to specify appointment ascendence inwards dorsum quotes . meet the illustration bash script  :

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

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

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

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

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

0 Response to "10 Examples Of Appointment Dominance Inwards Linux As Well As Unix"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel