I'm trying to create a simple script in linux shell that in a folderX goes through each of its folders, renames the files that finds there, and moves them to the root (folderX) folder.... I'm guessing that the logic is somewhat like this:
-0> //in folderX
-0>for each folder == $folderY //just the last part, what comes after ~/folderX/[this]
-1> cd ./$folderY
-1> for each fileInY == $fileInY //just the last part, what comes after ~/folderX/folderY/[this.something]
-2> rename fileInY = "$folderY - $fileInY"
-1> move * to folderX
-1> cd..
(but suggestions and different methods of approach are appreciated)
Thanks in advance! -Gabix
folder="folderX"
find "$folder" -type f -exec cp '{}' '{}'.bak \; -exec mv '{}'.bak "$folder" \;
Set the root folder/directory in a variable folder and then use this to run find and then exec. Find files in the directory structure and first copy the name of the file to the name of the file followed by ".bak" and then move the file from the directory to the root folder/directory