I am trying to add a function to a data collection bash script I am writing. The intention would be to point to a specific directory, and then cd into the NEWEST directory within the parents.
Pseudocode:
cd top_dir
    for each dir in top_dir:
      age = dir.age
      if age < least_age:
        least_age = age
        newest_dir = dir
    cd newest_dir
I have tried using cd "$( find "$1"/* -prune -type d 2>/dev/null | xargs stat -c "%Y %n" 2>/dev/null | sort -nr | head -n 1 | cut -d " " -f 2-)" from this post, but that instead cd's me into the newest directory on my computer.
The intention would be for a directory structure like below:
parent_dir:
  child_1 | Last Edited 1 Hr Ago
  child_2 | Last Edited 1 Yr Ago
  child_3 | Last Edited 2 Yr Ago
  child_4 | Last Edited 1 Min Ago
  child_5 | Last Edited 1 Week Ago
The command would cd me into child_4