I've used "dest-folder" here as the name of the destination directory. Be careful with these command lists, as they move files and might overwrite something without prompting.
This names the destination files dest-folder/<former directory name>-<filename>.
for i in folder*/*; do mv "$i" "dest-folder/$(dirname $i)-$(basename $i)"; done
These commands put an incremental number always in front of the file name:
for i in folder*; do let j++; for k in $i/*; do mv $k dest-folder/$j-$(basename $k); done; done
This uses a little trickery to put the icremental number only in the filenames that already exist:
mv -f --backup=t folder*/* dest-folder
for i in dest-folder/*~; do mv $i $(echo $i|sed -re 's/\/(.*).~(.*)~/\/\2-\1/'); done
The command sequences would be easier to understand if broken down into lines of code. The semicolon marks a place where you can press Return; the prompt changes until you give the last done
command. The do
s are usually also followed by a newline. If you want to write the commands into an executable file, write #!/bin/bash
as the first line, then every command on a separate line. When the file is saved use chmod +x filename
to change it into an executable. Then run it like this: ./filename