Skip to content

Instantly share code, notes, and snippets.

@hiranp
Created November 14, 2024 16:52
Show Gist options
  • Save hiranp/68ee794b34880ea5760ab3c9ad3a9cf6 to your computer and use it in GitHub Desktop.
Save hiranp/68ee794b34880ea5760ab3c9ad3a9cf6 to your computer and use it in GitHub Desktop.

Revisions

  1. hiranp revised this gist Nov 14, 2024. 1 changed file with 18 additions and 1 deletion.
    19 changes: 18 additions & 1 deletion copy_files_specific_date.sh
    Original file line number Diff line number Diff line change
    @@ -1 +1,18 @@
    ‎‎​
    #!/bin/bash

    # Define source and destination directories
    SOURCE_DIR="/path/to/source"
    DEST_DIR="/path/to/destination"
    START_DATE="2024-10-01" # Change this to the start date of the range
    END_DATE="2024-10-15" # Change this to the end date of the range
    EXTENSIONS=("*.txt" "*.log" "*.conf") # Add the specific extensions you want to match

    # Ensure the destination directory exists
    mkdir -p "$DEST_DIR"

    # Find and copy files with specific extensions and within the date range from SOURCE_DIR to DEST_DIR
    for EXT in "${EXTENSIONS[@]}"; do
    find "$SOURCE_DIR" -type f -name "$EXT" -newermt "$START_DATE" ! -newermt "$END_DATE +1 day" -exec cp --parents {} "$DEST_DIR" \;
    done

    echo "Files with specific extensions and within the date range have been copied from $SOURCE_DIR to $DEST_DIR."
  2. hiranp created this gist Nov 14, 2024.
    1 change: 1 addition & 0 deletions copy_files_specific_date.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ‎‎​