Bash Wiki
Posts (Latest 30 updated) :
Read all
Contents:
  1. [Linux] Bash date uso equivalente: Get the current date and time
    1. Overview
    2. Usage
    3. Common Options
    4. Common Examples
    5. Tips

[Linux] Bash date uso equivalente: Get the current date and time

Overview

The date command in Bash is used to display the current date and time in various formats. It can also be used to set the system date and time, although this typically requires administrative privileges.

Usage

The basic syntax of the date command is as follows:

date [options] [arguments]

Common Options

  • +FORMAT: Format the output according to the specified format string.
  • -u: Display the date in Coordinated Universal Time (UTC).
  • -d STRING: Display the date corresponding to the STRING instead of the current date.
  • -R: Output the date in RFC 2822 format.

Common Examples

  1. Display the current date and time:
    date
    
  2. Display the date in a custom format:
    date "+%Y-%m-%d %H:%M:%S"
    
  3. Display the current date in UTC:
    date -u
    
  4. Display a specific date:
    date -d "2023-10-01"
    
  5. Display the date in RFC 2822 format:
    date -R
    

Tips

  • Use the +FORMAT option to customize the output to suit your needs, such as including only the year, month, or day.
  • To see all available format options, you can refer to the man date command in your terminal.
  • Remember that changing the system date and time usually requires superuser privileges, so use caution when using the date command for setting the date.