Skip to content

Instantly share code, notes, and snippets.

@kekneus373
Created January 12, 2026 15:16
Show Gist options
  • Select an option

  • Save kekneus373/96fe4c5ef4e4e12dea39fee6495cdef5 to your computer and use it in GitHub Desktop.

Select an option

Save kekneus373/96fe4c5ef4e4e12dea39fee6495cdef5 to your computer and use it in GitHub Desktop.
[bash] Efficiently gather dates for logging activity in scripts

You can use the date command to include the current date and time in your echo statements. Here are a few common examples:

1. Basic timestamp (date and time):

echo "Converted: $filename$output at $(date)"

2. Custom format (e.g., YYYY-MM-DD HH:MM:SS):

echo "Converted: $filename$output at $(date +'%Y-%m-%d %H:%M:%S')"

3. Only the date:

echo "Converted: $filename$output on $(date +'%Y-%m-%d')"

4. Include both date and time in a single line:

echo "Converted: $filename$output on $(date +'%Y-%m-%d') at $(date +'%H:%M:%S')"

Example with your script:

echo "Converted: $filename$output at $(date +'%Y-%m-%d %H:%M:%S')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment