7:26 PM 15 Great DATE command examples |
Appear for online test on Date and system related QUIZ The best way to understand date and time of the system is to explore several examples. So, we are exercising some common date commands here: 1.To print the date of the day before yesterday: date --date='2 days ago'
2.Set the system clock forwared by four minutes date --set='+4 minutes' 3.To print the date of the day four months and two days later: date --date='4 months 2 days'
4. To print the day of Christmas in the current year: date --date='25 Dec' +%j
5. Create a backup of file with current system timestamp Using date command with the formats(%d,%m, %y, %s ....), we can take a backup of the file as shown below:
6.To print the current full month name and the day of the month: date '+%B %d'
But lets say if we want to remove extra zero from date 01 to 09, we can use '-'flag. For example `date -d 1apr '+%B %d'' will print `Apr 01'.
7.To print a date without the leading zero for one-digit days of the month, we can use the (GNU extension) `-' flag to suppress the padding: date -d 1may '+%B %-d
8.To print the current date and time in the format required by many non-GNU versions of `date' when setting the system clock: date +%m%d%H%M%Y.%S
9. To set the system clock forward by two minutes: date --set='+2 minutes'
You must be a priviledged user to change date setting of the system.
We can use the `--date' option with the `%s' format. The command to print number of seconds two minutes after epoch.
12. Print the system time zone of the system
13. To check the last modification date and time of a file. date -r filename
14. To print the date of yesterday or tomorrow
15. To print the universal time (UTC)
FORMAT supported by date comand for different output %% a literal % %a locale's abbreviated weekday name (e.g., Sun) %A locale's full weekday name (e.g., Sunday) %b locale's abbreviated month name (e.g., Jan) %B locale's full month name (e.g., January) %c locale's date and time (e.g., Thu Mar 3 23:05:25 2005) %C century; like %Y, except omit last two digits (e.g., 20) %d day of month (e.g., 01) %D date; same as %m/%d/%y %e day of month, space padded; same as %_d %F full date; same as %Y-%m-%d %g last two digits of year of ISO week number (see %G) %G year of ISO week number (see %V); normally useful only with %V %h same as %b %H hour (00..23) %I hour (01..12) %j day of year (001..366) %k hour ( 0..23) %l hour ( 1..12) %m month (01..12) %M minute (00..59) %n a newline %p locale's equivalent of either AM or PM; blank if not known %P like %p, but lower case %r locale's 12-hour clock time (e.g., 11:11:04 PM) %R 24-hour hour and minute; same as %H:%M %s seconds since 1970-01-01 00:00:00 UTC %S second (00..60) %t a tab %T time; same as %H:%M:%S %u day of week (1..7); 1 is Monday %U week number of year, with Sunday as first day of week (00..53) %V ISO week number, with Monday as first day of week (01..53) %w day of week (0..6); 0 is Sunday %W week number of year, with Monday as first day of week (00..53) %x locale's date representation (e.g., 12/31/99) %X locale's time representation (e.g., 23:13:48) %y last two digits of year (00..99) %Y year %z +hhmm numeric time zone (e.g., -0400) %:z +hh:mm numeric time zone (e.g., -04:00) %:z +hh:mm numeric time zone (e.g., -04:00) %::z +hh:mm:ss numeric time zone (e.g., -04:00:00) %:::z numeric time zone with : to necessary precision (e.g., -04, +05:30) %Z alphabetic time zone abbreviation (e.g., EDT) By default, date pads numeric fields with zeroes. The following optional flags may follow `%': - (hyphen) do not pad the field _ (underscore) pad with spaces 0 (zero) pad with zeros ^ use upper case if possible # use opposite case if possible Appear for online test on Date and system related QUIZ
|
|
Related blogs
You may also like to see:
[2014-11-19] | [Open System-Linux] |
ETHTOOL : A tool in Linux to display or change ethernet card setting |
[2014-04-10] | [Open System-Linux] |
SED command for filtering and transforming texts of a file using regular expression |
[2014-10-25] | [Open System-Linux] |
XMLWF command in Linux to check/validate/parse an XML file |
[2016-01-23] | [Open System-Linux] |
Some useful examples of netstat command in Linux for network statistics |
[2015-08-18] | [Open System-Linux] |
How to open a PDF file or a Postscript file in Linux - Evince Document viewer? |
Total comments: 0 | |