Last active
February 22, 2022 22:39
-
-
Save lstellway/66fdbd3b25cd214fbc4825ee7e9e9348 to your computer and use it in GitHub Desktop.
Distribute files in a directory to subfolders based on URL's in a specified file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Loop through links | |
while IFS="" read -r LINE || [ -n "$LINE" ]; do | |
# Replace domain (everything before "/media") | |
PATH=${LINE//**\/media/media} | |
# Get file file name (everything after the last "/") | |
FILE_NAME=${PATH//*\//} | |
# Remove the last "/" and filename from the path | |
PATH=${PATH/\/$FILE_NAME/} | |
# Create the directory | |
mkdir -p $PATH | |
# Copy the file to the directory | |
cp $FILE_NAME $PATH | |
echo "Moved ${FILE_NAME} to ${PATH}." | |
done < $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
Data File (
images.txt
):Working Directory:
Command: