How to format output?

0132

You can format the output of the date command in Bash using format specifiers. Here are some common specifiers you can use:

  • %Y: Year (e.g., 2023)
  • %m: Month (01 to 12)
  • %d: Day of the month (01 to 31)
  • %H: Hour (00 to 23)
  • %M: Minute (00 to 59)
  • %S: Second (00 to 59)
  • %A: Full weekday name (e.g., Monday)
  • %B: Full month name (e.g., January)

Example of Formatting Output

To display the date and time in a custom format, you can combine these specifiers. For example:

date +"%A, %B %d, %Y %H:%M:%S"

This will output something like:

Friday, October 13, 2023 14:30:00

Custom Formats

You can create any format you like by mixing and matching these specifiers. For instance, to display just the date in MM/DD/YYYY format:

date +"%m/%d/%Y"

This will output:

10/13/2023

Feel free to ask if you need more specific formatting examples or have other questions!

0 Comments

no data
Be the first to share your comment!