Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
562 B
1
Indexable
Never
#!/bin/bash

# Define the source and target directories
source_dir="/path/to/source"
target_dir="/path/to/target"

# Find and move files with a specific ending
find "$source_dir" -type f -name "*.txt" -exec sh -c '
  for file; do
    # Compute the subdirectory path by removing the source directory prefix and filename
    sub_dir=$(dirname "${file#$source_dir}")

    # Create the corresponding subdirectory in the target location
    mkdir -p "$target_dir$sub_dir"

    # Move the file to the new location
    mv "$file" "$target_dir$sub_dir/"
  done
' sh {} +
Leave a Comment