
Look at the file again, and when you are positive that it's what you want, execute it with sh /tmp/bulk-rename. That file now contains a lot of lines like mv -n "foo" "bar" mv -n prevents overwriting an existing file. The sed part adds a mv -n to the start of each of those lines. What that paste command does is it takes one line from /tmp/old.txt and one line from /tmp/new.txt and puts them together on one single line with a blank between them. Then put the files together with the paste command and change each line to a mv command: paste /tmp/old.txt /tmp/new.txt | sed -e 's/^/mv -n /' >/tmp/bulk-rename In any case, have a good hard look at /tmp/new.txt to see if it's really what you want the new names to look like.Ĭheck for duplicate names! ( sort /tmp/new.txt | uniq -r) Make sure there are no duplicates and if there are, edit that line manually to get a unique name. Important: do not change the order in that file, and do not delete or add any line! Then replace unwanted characters in /tmp/new.txt, either manually with an editor or with sed -i -e (or perl -p -i -e if you prefer that) or tr or tr -d. it will give you "foo*bar" or "foo | bar". Ls -Q will add double quotes around each name, i.e. I'll happily give further comment.In general, mmv is great at mass-renaming tasks.īut in this particular case, I'd go a completely different route: Generate a shell script with a couple of shell commands, have a close look at it if it's really what I want, and then execute it.

After that, we want to run (the same script or a different one) it to actually make the changes.Īll I need is stated above, so anything marked "MAKE -" needs to become a hyphen and anything marked "REMOVE" needs to just go away. This will allow us to review the results and make sure there are no stuff-ups. The above command will rename the file name TESTA.txt to TESTB.txt. Note The quotation marks in the command are only required if the name includes spaces.

Basically I need to be able to run a script to output all the changes that will be made to a file, before anything is changed. Navigate to your path where you need to rename the file by type cd and the path. There aren't any additional requirements. This means I have to use pure bash to perform the operation. The rename command is not available on our servers at all. I'm sure he has his reasons, but I can't say that I'm privy to them. I'm unable to use any version of rename, the head of my IT dept.

:max_bytes(150000):strip_icc()/Batch_Rename_Files_08-3415890854e04d9a9b945967c99d170d.jpg)
The script would then either need to be modified slightly to use mv instead, or it could refer to the file created using echo and perform all the necessary changes using it.Īny and all help would be appreciated as this is really rather important and I lack the skills at this point in time to make this myself.Ī final note, I can't use the #rename command.
#BATCH FILE RENAME REMOVE LAST CHARACTER FULL#
Ideally the script would run the first time and produce a file using echo with all the changes that need to be made including the full path and then the changed path.
#BATCH FILE RENAME REMOVE LAST CHARACTER HOW TO#
For example, I can create a script to remove only from file names, but I don't know how to include folders/directories nor do I know how to include all the other characters in this one script. I know how to make simple versions, that can only change file names on a case by case basis but can't do it en mass. This is a rather important step in a very large project we have going in our organisation, and I haven't been able to create a script thus far. If the character is flagged as "REMOVE" then it should be removed, and nothing be put in it's place, for example a file named John?Sykes.doc would become JohnSykes.doc REMOVE character with "MAKE -" next to it needs to be made a - (hyphen) in place of the character, for example a file named John\Sykes.doc needs to become John-Sykes.doc. I need an assist here, got a project going where we need to modify file & folder names within a specific directory in order to remove or replace any and all characters which would be considered illegal under Windows, with a few additional characters.
