getdate_err - Linux


getdate_err is a command-line utility designed to extract date and time information from a specified input file or standard input. It offers advanced error-handling capabilities, allowing users to handle invalid date formats and missing data effectively.


getdate_err [OPTIONS] [FILE...]


| Option | Description | Default |
| -a, –access | Retrieve the access time | N/A |
| -c, –create | Retrieve the creation time | N/A |
| -m, –modify | Retrieve the modification time | N/A |
| -b, –birthdate | Retrieve the birthdate from a POSIX file (if available) | N/A |
| -n, –null-input | Treat input as null-terminated strings, separating dates by newlines | N/A |
| -f, –file | Specifies an input file to extract date from. Multiple files can be specified. | N/A |
| -p, –pattern | Custom date format to use when parsing. See strftime for formatting options. | %Y-%m-%d %H:%M:%S |
| -e, –error | Error handling mode:
ignore: Ignore errors and continue with processing.
warn: Display a warning message for each error.
stop: Stop processing and exit with an error code. | ignore |
| -d, –delimiter | Delimiter used to separate dates within the input file (when not using -n). | \n |
| -h, –help | Display usage information and exit. | N/A |
| -V, –version | Display version information and exit. | N/A |


Extract modification time from a file:

getdate_err -m file.txt

Retrieve birthdate from a POSIX file:

getdate_err -b /usr/bin/ls

Parse dates with a custom format:

getdate_err -p %d/%m/%Y input.txt

Handle errors:

Ignore errors:

getdate_err -e ignore invalid.txt

Warn about errors:

getdate_err -e warn invalid.txt

Stop on the first error:

getdate_err -e stop invalid.txt

Common Issues

  • Invalid date formats: Ensure the date format specified with -p matches the format of dates in the input file.
  • Missing dates: If a file does not contain a valid date, an error will be raised depending on the specified error handling mode.
  • Empty files: If the input file is empty, no date information can be extracted.


Combine with other commands:

Extract modification time and pass it to another command:

find . -type f -mmin -1 | getdate_err -m | sort

Use in scripts:

Extract dates within a script and perform conditional actions:


for file in *.txt; do
  date=$(getdate_err -m $file)
  if [[ $date > "2023-01-01" ]]; then
    echo "File $file was modified after 2023-01-01"

Related Commands

  • date: Display or set the system date and time.
  • strptime: Convert a date and time string to a structured tm representation.
  • strftime: Convert a tm representation to a date and time string.