Untitled
unknown
plain_text
a year ago
562 B
5
Indexable
#!/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 {} +
Editor is loading...
Leave a Comment