I have a collection of files at ./date-and-time/fixed/path/filename
where date-and-time
and filename
are variable. I would like to move all these files to ./filename/date-and-time
. The former path is the filename and the former filename is the path. Is there a good way to do this? There are ~1000 files in total with ~100 distinct filenames.
Something like this should work (note I have echo
ed the actual commands; please check carefully that it is doing the right thing before removing them)
#!/bin/bash
shopt -s nullglob
for file in */fixed/path/*; do
[[ -f "$file" ]] || continue
f="${file##*/}"; d="${file%%/*}"
echo mkdir -p "$f" && echo mv --no-clobber -- "$file" "$f/$d"
done
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments