Skip to main content
added 77 characters in body
Source Link
Jetchisel
  • 1.6k
  • 9
  • 12

One way with bash, files in between 20:00 and 22:00

#!/usr/bin/env bash

for f in /folder/x/*.bak; do
  var=$(date -r "$f" '+%H:%M')
  if [[ $var > '20:00' && $var < '22:00' ]]; then                                                                                                                                          
    echo "$f"
  fi
done

The above code should match your files.

That date syntax works on both GNU and BSD date(1)

  • The above code should match your files.
  • Just change to [[ $var < '20:15' ]] If that's just what you're after.
  • That date syntax works on both GNU and BSD date(1)

EDIT: Updated answer

One way with bash, files in between 20:00 and 22:00

#!/usr/bin/env bash

for f in /folder/x/*.bak; do
  var=$(date -r "$f" '+%H:%M')
  if [[ $var > '20:00' && $var < '22:00' ]]; then                                                                                                                                          
    echo "$f"
  fi
done

The above code should match your files.

That date syntax works on both GNU and BSD date(1)


EDIT: Updated answer

One way with bash, files in between 20:00 and 22:00

#!/usr/bin/env bash

for f in /folder/x/*.bak; do
  var=$(date -r "$f" '+%H:%M')
  if [[ $var > '20:00' && $var < '22:00' ]]; then                                                                                                                                          
    echo "$f"
  fi
done
  • The above code should match your files.
  • Just change to [[ $var < '20:15' ]] If that's just what you're after.
  • That date syntax works on both GNU and BSD date(1)

EDIT: Updated answer

added 6 characters in body
Source Link
Jetchisel
  • 1.6k
  • 9
  • 12

One way with bash, files in between 20:00 and 22:00

#!/usr/bin/env bash

for f in dir/folder/x/*.bak; do
  var=$(date -r "$f" '+%H:%M')
  if [[ $var > '20:00' && $var < '22:00' ]]; then                                                                                                                                          
    echo "$f"
  fi
done

The above code should match your files.

That date syntax works on both GNU and BSD date(1)


EDIT: Updated answer

One way with bash, files in between 20:00 and 22:00

#!/usr/bin/env bash

for f in dir/*.bak; do
  var=$(date -r "$f" '+%H:%M')
  if [[ $var > '20:00' && $var < '22:00' ]]; then                                                                                                                                          
    echo "$f"
  fi
done

The above code should match your files.

That date syntax works on both GNU and BSD date(1)


EDIT: Updated answer

One way with bash, files in between 20:00 and 22:00

#!/usr/bin/env bash

for f in /folder/x/*.bak; do
  var=$(date -r "$f" '+%H:%M')
  if [[ $var > '20:00' && $var < '22:00' ]]; then                                                                                                                                          
    echo "$f"
  fi
done

The above code should match your files.

That date syntax works on both GNU and BSD date(1)


EDIT: Updated answer

change %I to %H
Source Link
Jetchisel
  • 1.6k
  • 9
  • 12

One way with bash, files in between 20:00 and 22:00

#!/usr/bin/env bash

for f in dir/*.bak; do
  var=$(date -r "$f" '+%I'+%H:%M')
  if [[ $var > '20:00' && $var < '22:00' ]]; then                                                                                                                                          
    echo "$f"
  fi
done

The above code should match your files.

That date syntax works on both GNU and BSD date(1)


EDIT: Updated answer

One way with bash, files in between 20:00 and 22:00

#!/usr/bin/env bash

for f in dir/*.bak; do
  var=$(date -r "$f" '+%I:%M')
  if [[ $var > '20:00' && $var < '22:00' ]]; then                                                                                                                                          
    echo "$f"
  fi
done

The above code should match your files.

That date syntax works on both GNU and BSD date(1)


EDIT: Updated answer

One way with bash, files in between 20:00 and 22:00

#!/usr/bin/env bash

for f in dir/*.bak; do
  var=$(date -r "$f" '+%H:%M')
  if [[ $var > '20:00' && $var < '22:00' ]]; then                                                                                                                                          
    echo "$f"
  fi
done

The above code should match your files.

That date syntax works on both GNU and BSD date(1)


EDIT: Updated answer

Updated answer
Source Link
Jetchisel
  • 1.6k
  • 9
  • 12
Loading
Missing $ at the BASH_REMATCH
Source Link
Jetchisel
  • 1.6k
  • 9
  • 12
Loading
change printf at the second example
Source Link
Jetchisel
  • 1.6k
  • 9
  • 12
Loading
Source Link
Jetchisel
  • 1.6k
  • 9
  • 12
Loading