10 Examples Of Appointment Ascendence Inward Linux Together With Unix

Date ascendence inwards unix or Linux is 1 of of import ascendence to acquire together with main because nosotros ever necessitate engagement information. no affair you lot desire to know current engagement inwards unix or your bash script needs electrical flow engagement inwards unix for archiving role you lot necessitate to exercise engagement command. In its simplest format engagement ascendence shows the current engagement together with time inwards unix piece amongst sophisticated selection nosotros tin extract many useful information from unix engagement command. In this Unix ascendence tutorial  we volition run across some useful tips on using date ascendence inwards unix together with acquire to a greater extent than but about engagement inwards unix together with Linux. One of import thing to banking concern notation is that dissimilar implementation of unix engagement ascendence may non hold upward precisely same e.g. AIX version of engagement ascendence doesn't back upward selection "-d" or "date". Anyway let's run across some illustration of unix engagement command:

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


1) Example 1 -  displaying electrical flow engagement together with fourth dimension inwards Unix
This is simplest exercise of unix engagement command. but type engagement inwards the ascendence prompt together with it volition exhibit you lot the electrical flow engagement together with fourth dimension inwards the timezone your machine is.

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



2) Example 2 - displaying Julian engagement inwards Unix
 or Linux is 1 of of import ascendence to acquire together with main because nosotros ever necessitate engagement information 10 Examples of Date Command inwards Linux together with UNIXmost of coffee stock trading application running nether Linux exercise Julian engagement format to shop engagement information. Julian dates are made of v digits 2 of which correspond twelvemonth together with 3 or concluding digit correspond twenty-four threescore minutes catamenia of year. for illustration 14th July 20111 volition hold upward represented past times 11195 inwards Julian format because 14th July is the 195th twenty-four threescore minutes catamenia of the year. nosotros tin acquire Julian engagement past times using engagement ascendence inwards unix equally shown inwards the below illustration of unix engagement 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 engagement or tomorrow's Julian engagement inwards Unix though I conduct maintain heard that "-d" selection of engagement is non supported inwards AIX together with then this may non travel inwards AIX version of Unix.


3) Example 3 - displaying electrical flow engagement inwards diverse format inwards unix
Unix engagement ascendence is really powerful together with tin exhibit engagement inwards diverse format. inwards this department of unix engagement tutorial nosotros volition convert engagement into some normally used engagement 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 exercise %y (small letter) for displaying but 2 digit of year)  %m  shows 2 digit of calendar month equally 01..12 together with %d correspond twenty-four threescore minutes catamenia of month.

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

here over again %d is for twenty-four threescore minutes catamenia %m is for calendar month together with %Y is for 4 digit twelvemonth if you lot desire to exhibit 2 digit exercise 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 higher upward approach but chaged the "/" to "-", you lot tin modify it to whatever grapheme equally per your wishing together with until unix convey it.


displaying engagement inwards MM/DD/YYYY format inwards Unix
what create you lot guys intend would it hold upward hard no correct ? but telephone commutation house of "%m" together with "%d" together with you lot are gear upward equally shown inwards below illustration of engagement ascendence inwards unix

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

displaying engagement inwards YYYY-MM-DD format is precisely like to higher upward approach but modify the social club of twelvemonth together with month.


4) How to detect engagement seven days earlier electrical flow engagement inwards Unix
This is actually squeamish of gnu version of unix engagement command you lot tin easily acquire what's the engagement 4 days earlier or v days earlier past times using engagement ascendence inwards unix. hither is example:

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

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


5) How to acquire engagement seven days afterwards electrical flow twenty-four threescore minutes catamenia inwards Unix together with Linux
As shown higher upward you lot tin acquire the engagement afterwards seven days inwards unix past times using gnu version of engagement ascendence inwards unix, hither is an illustration of getting engagement seven days afterwards electrical flow date:

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

this means you lot tin detect whatever engagement which is seven days past times of a given electrical flow engagement inwards unix


6) Setting engagement fourth dimension into unix
setting engagement is slow though I don't recommend to create it if you lot conduct maintain unix admins. Also changing engagement requires origin access which you lot mightiness non conduct maintain amongst you lot anyway nosotros tin exercise unix engagement ascendence to modify the date, but render novel engagement inwards the specified format together with your electrical flow engagement volition hold upward laid to novel date.

format of setting engagement fourth dimension into unix

date mmddhhmi

where mm = month
      dd = twenty-four threescore minutes catamenia of month
      hh = hour
      mi = minute
  
Example of changing engagement fourth dimension inwards unix

/java date 07240222
Lord's Day Jul 24 02:22:00 MPST 2011

above example of engagement command volition laid the electrical flow engagement to 24th July together with fourth dimension to 02:22, nosotros don't render twelvemonth information together with engagement uses electrical flow twelvemonth past times default.

7) How to detect timezone past times using unix engagement ascendence - Example
unix engagement ascendence tin 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 run across some illustration of unix engagement 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 exhibit twenty-four threescore minutes catamenia of calendar week inwards Unix using engagement ascendence - Exmaple
you tin exhibit electrical flow date, twenty-four threescore minutes catamenia of calendar week holler using unix engagement command  past times using options "%a" together with "%A". pocket-size instance is used to display twenty-four threescore minutes catamenia inwards curt format piece majuscule 1 is used to display total holler of day. run across the below illustration of engagement ascendence inwards unix for display twenty-four threescore minutes catamenia 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 acquire from unix engagement command. past times default engagement ascendence inwards unix display both engagement together with fourth dimension information but nosotros tin exercise diverse options provided past times engagement ascendence to display entirely fourth dimension information. let's run across some illustration of showing fourth dimension using unix engagement command:

10) Date to ascendence for showing fourth dimension inwards format HH:MM:SS
As shown higher upward on showing engagement inwards dissimilar format inwards unix you lot tin equally good display fourth dimension on dissimilar format past times applying same approach. you lot but necessitate to retrieve next fourth dimension related options of unix engagement command

%H   threescore 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 engagement ascendence inwards unix afterwards going through together with trying these examples. you lot tin acquire to a greater extent than information nigh engagement ascendence inwards unix past times using "man date" or "date --help" which volition equally good listing all the options supported past times unix engagement command.

Tip: but retrieve that unix engagement command is generally used within bash script to acquire the engagement information , together with then its worth mentioning hither how to execute engagement ascendence from bash script, you lot but necessitate to specify engagement ascendence inwards dorsum quotes . run across the illustration bash script  :

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

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

/java ./unixdate.sh
Current date: Lord's Day Jul 24 02:30:50 MPST 2011

So that was all nigh dissimilar examples of engagement command. We conduct maintain seen how nosotros tin format engagement inwards Unix, how nosotros tin convert engagement into dissimilar timezone inwards Unix, how nosotros tin acquire electrical flow engagement together with fourth dimension within bash script together with several other examples of engagement command. Let me know if you lot conduct maintain whatever other usage of engagement ascendence which is non covered here.

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

Sumber https://javarevisited.blogspot.com/

0 Response to "10 Examples Of Appointment Ascendence Inward Linux Together With Unix"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel