Bash 2. Improve this answer. SiegeX SiegeX k 22 22 gold badges silver badges bronze badges. It's good that you came up with a solution that does all of those things Code Duck: Adding recursive capability was a trivial task and one should never assume anything about filenames, always treat them as if they include newlines or other nasties.
The second you do not is when somebody adds one that breaks your script horribly and does god knows what. Show 2 more comments. The mmv program was installed as part of my CygWin but I had to sudo apt-get install mmv on my Ubuntu box to get it down.
Mark, not much effort adding a test for directory. Because your code does not traverse into subdirectories. Its just the idea and not the FULL solution but you get the point. Rob Curtis Rob Curtis 1 1 silver badge 6 6 bronze badges. This does not handle filenames with spaces or newlines. Also does not work with files in subdirectories as it moves the file in the subdirectory into the top-level directory.
Epsilon Prime Epsilon Prime 4, 5 5 gold badges 30 30 silver badges 34 34 bronze badges. One should mention the mmv tool, which is especially made for this. Carl Smotricz Carl Smotricz I think askvictor kinda beat ya to it there mate. Yeah, he was in such a hurry he didn't name the main tool from the bunch. I honestly independently found the same link searching for the tool I had in mind; and since I feel my answer is the more useful, I'm leaving it up.
Yes: Rock Linux includes mmv; but that doesn't help much because it's a fairly obscure distro. James Morris James Morris 4, 3 3 gold badges 28 28 silver badges 49 49 bronze badges.
The name of the original file and the name of the renamed file will be taken as the input from the user in the following script. The file will be renamed if the original filename exists. If any file with the renamed filename already exists, then the old file will be overwritten by the content of the newly renamed file. The following script will ask for permission from the user to overwrite before doing the renaming task.
Multiple files can be renamed at once by using a regular expression. If the search text is found, then the files will be renamed by the replacement text. The following script can be used to rename multiple files by using a regular expression pattern that will take the extension of the searched filename and the renamed filename as the inputs. Connect and share knowledge within a single location that is structured and easy to search.
Since you said that rename is not installed on your system, here's a solution that uses more standard Bash:. Explanation: We loop over all files. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Learn more. Renaming all files in folder in Bash [duplicate] Ask Question. Asked 4 years, 5 months ago.
0コメント