10 Examples Of Appointment Ascendance Inwards Linux Too Unix

Date ascendence inward unix or Linux is i of of import ascendence to acquire in addition to main because nosotros e'er ask appointment information. no affair you lot desire to know current appointment inward unix or your bash script needs electrical flow appointment inward unix for archiving role you lot ask to utilization appointment command. In its simplest format appointment ascendence shows the current appointment in addition to time inward unix field amongst sophisticated pick nosotros tin extract many useful information from unix appointment command. In this Unix ascendence tutorial  we volition run across some useful tips on using date ascendence inward unix in addition to acquire to a greater extent than or in addition to then appointment inward unix in addition to Linux. One of import thing to greenback is that dissimilar implementation of unix appointment ascendence may non hold upward just same e.g. AIX version of appointment ascendence doesn't back upward pick "-d" or "date". Anyway let's run across some instance of unix appointment command:

By the agency this is 5th article inward my serial of roofing examples of of import in addition to oftentimes used commands e.g. find examples, grep examples, chmod example in addition to sort ascendence example.


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

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



2) Example 2 - displaying Julian appointment inward Unix
 or Linux is i of of import ascendence to acquire in addition to main because nosotros e'er ask appointment information 10 Examples of Date Command inward 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 yr in addition to iii or concluding digit correspond twenty-four hr menses of year. for instance 14th July 20111 volition hold upward represented yesteryear 11195 inward Julian format because 14th July is the 195th twenty-four hr menses of the year. nosotros tin acquire Julian appointment yesteryear using appointment ascendence inward unix equally shown inward 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 agency you lot tin acquire yesterdays Julian appointment or tomorrow's Julian appointment inward Unix though I lead keep heard that "-d" pick of appointment is non supported inward AIX in addition to then this may non operate inward AIX version of Unix.


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

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

here %Y shows yr inward 4 digit ( you lot tin utilization %y (small letter) for displaying simply 2 digit of year)  %m  shows 2 digit of calendar month equally 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 i time again %d is for twenty-four hr menses %m is for calendar month in addition to %Y is for 4 digit yr if you lot desire to exhibit 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 alter it to whatsoever grapheme equally per your want in addition to until unix convey it.


displaying appointment inward MM/DD/YYYY format inward Unix
what create you lot guys intend would it hold upward hard no correct ? simply telephone substitution house of "%m" in addition to "%d" in addition to you lot are create equally shown inward below instance of appointment ascendence inward unix

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

displaying appointment inward YYYY-MM-DD format is just like to to a higher house approach simply alter the companionship of yr in addition to month.


4) How to detect appointment seven days earlier electrical flow appointment inward 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 ascendence inward unix. hither is example:

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

by using this agency you lot tin detect whatsoever appointment which is whatsoever days apart from a given electrical flow appointment inward unix


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

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

this agency you lot tin detect whatsoever appointment which is seven days yesteryear of a given electrical flow appointment inward unix


6) Setting appointment fourth dimension into unix
setting appointment is slow though I don't recommend to create it if you lot lead keep unix admins. Also changing appointment requires source access which you lot mightiness non lead keep amongst you lot anyway nosotros tin utilization unix appointment ascendence to alter the date, simply render novel appointment inward the specified format in addition to 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 hr menses of month
      hh = hour
      mi = minute
  
Example of changing appointment fourth dimension inward 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 in addition to fourth dimension to 02:22, nosotros don't render yr information in addition to appointment uses electrical flow yr yesteryear default.

7) How to detect timezone yesteryear using unix appointment ascendence - Example
unix appointment ascendence tin display timezone related information also. it provides next pick 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 run across some instance 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 pick of unix date command volition display timezone respective of GMT)
+0800


8) How to exhibit twenty-four hr menses of calendar week inward Unix using appointment ascendence - Exmaple
you tin exhibit electrical flow date, twenty-four hr menses of calendar week yell using unix appointment command  yesteryear using options "%a" in addition to "%A". pocket-size instance is used to display twenty-four hr menses inward curt format field upper-case missive of the alphabet i is used to display total yell of day. run across the below instance of appointment ascendence inward unix for display twenty-four hr menses of calendar week :

/java date +%a
Thu

/java date +%A
Thursday


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

10) Date to ascendence for showing fourth dimension inward format HH:MM:SS
As shown to a higher house on showing appointment inward dissimilar format inward unix you lot tin equally good display fourth dimension on dissimilar format yesteryear applying same approach. you lot simply ask to yell back 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 straight off guys I promise you lot volition hold upward to a greater extent than comfortable amongst appointment ascendence inward unix later going through in addition to trying these examples. you lot tin acquire to a greater extent than information virtually appointment ascendence inward unix yesteryear using "man date" or "date --help" which volition equally good listing all the options supported yesteryear unix appointment command.

Tip: simply yell back that unix appointment command is by in addition to large used within bash script to acquire the appointment information , in addition to then its worth mentioning hither how to execute appointment ascendence from bash script, you lot simply ask to specify appointment ascendence inward dorsum quotes . run across the instance 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 virtually dissimilar examples of appointment command. We lead keep seen how nosotros tin format appointment inward Unix, how nosotros tin convert appointment into dissimilar timezone inward 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 lead keep whatsoever other usage of appointment ascendence which is non covered here.

Further Learning
Linux Command Line Basics
How to detect IP address from hostname inward Linux

0 Response to "10 Examples Of Appointment Ascendance Inwards Linux Too Unix"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel