I have a GB's worth of music on my HDD that was formatted with EXT4. I want to move these files to a FAT formatted HDD partition. However, I can't move most of my files because they have ":" in the names (For example, "Act 2: ....." for operas). Is there a way with command line to rename all of my files from "XXXX:XXXX" to "XXXX-XXXX"?
If all your files are in a single directory, try:
(where * can be changed to something more restrictive if you'd like)
If you have many files in a directory tree, try this from the base of the tree:
You can add the option
-n
right afterrename
to have it tell you what it WOULD do without ACTUALLY doing it. This might help you avoid accidentally stepping on other files or something else bad...This is a solution in python which handles the case where the files are not necessarily in the same directory.
rootdir
to the outermost directory under consideration (Use complete path name starting with /. No shorthands or env variables like ~ allowed). No need to put \ before special characters - for example if the outermost dir is /.../My HDD, putrootdir = "/.../My HDD"
NOTrootdir = "/.../My\ HDD"
(Note the "s) [I'm being this explicit only because you may be unfamiliar with python. No disrespect intended.]logfile
to desired location of logfile. In the end, this file will contain the list of files renamed - for future reference.python rename.py
.Warning: Do test on a small sample before risking an entire GB of music.
Details: Renaming is performed from the innermost files outward.
Im not at my linux machine right now so I can only give rough information.
Linux has a commandline utility called
rename
which works with among other inputs, regular expressions or regexes. You should be able to use that along with a regex like "s/:/-/" on your files to achieve the rename you want.Just to be safe, do it in small batches and/or first test with the simulation (rename has a flag which just gives you the oldname and new name of the file without actually renaming - use this to verify first)
I realize this is a very old post. AeroGT80's recursive solution is very thorough, but it is pretty slow. I had it running for about half an hour on a slower server and it only got about half done - I think it was about 73,000 files in about 300 sub-directories.
The solution below will operate much quicker (it operates on all files in a directory, instead of each file one-by-one - using AeroGT80's non-recursive solution). The only problem is, it only goes down one directory deep (so it's not fully recursive like his solution is), but I'm sure it could be modified easily enough.