Skip to content

Instantly share code, notes, and snippets.

@mkdizajn
Created March 23, 2024 16:36
Show Gist options
  • Save mkdizajn/d9721404a81ffc30d009d8b94080272b to your computer and use it in GitHub Desktop.
Save mkdizajn/d9721404a81ffc30d009d8b94080272b to your computer and use it in GitHub Desktop.
BASH_ make items in subdirs flat in top dir
# >>>>>>>>>
# script to copy this structure - TO NEW DIRECTORY:
# slike1
# ├── 12063DSC04233.JPG
# ├── 27454DSC04230.JPG
# └── sub1
# ├── 15997DSC04140.JPG
# └── sub12
# └── 25022DSC04150.JPG
# <<<<<<<<<
# to this structure (note random file prefix for legit dups):
# slike2
# ├── 10892-25022DSC04150.JPG
# ├── 19939-15997DSC04140.JPG
# ├── 21121-27454DSC04230.JPG
# └── 22714-12063DSC04233.JPG
find ./slike/* -type f |
while IFS= read -r name; do # Read one line and store it in variable $name
cp "${name}" "./slike1/$RANDOM-${name##*/}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment