Discussion on:

11
Comments

Join the conversation!

Follow via:
RSS
Email Alert
0 Votes
+ -
detox
cflange 10th Oct 2011
You can also use 'detox *' or 'detox -r *' for recursive fixing. Unfortunately it also translates the accents from other languages (which may require option '-s iso8859_1' or '-s utf-8' to work correctly). Always test first with a dry-run (option -n).
0 Votes
+ -
Contributr
When I first wrote this script, it was because I had never heard of detox (in spite of several searches I did make for name cleaning command line utilities). When I discovered it, I kept using my script, because it's more portable and flexible. It uses utilities surely available on every Linux distributions; it also fixes directory names, something that (at least, according to its own man page) detox doesn't do. Finally, if you know just a little bit of Perl you can rename files in any way you can put in a regular expression (for example this_is_ME_iN_1998.JPG??? to This_Is_Me_In_1998.jpg???) , which you can't with detox

Thanks for mentioning it, though!

Marco
0 Votes
+ -
detox does directories at least one level deep.
$ detox --dry-run B*
Bad Name@spaces -> Bad_Name_spaces
Bad Name@spaces/What*kind!of stupid@name-is-this -> Bad Name@spaces/What_kind_of_stupid_name-is-this

I hadn't heard of detox before seeing this posting, but I tried it on cygwin and linux.
A little annoying to have to load lex and yacc, two of my least favorite topics, and the lowest grade I received in college ;-(

but it handles a directory at the top level with a bad name.
$ your_script 'Bad Name@spaces'
line 7: cd: Bad: No such file or directory

I had to back up to a good directory for this script to rename the "Bad" directory, as well as the underlying file that detox cleaned.
0 Votes
+ -
question
pgit 11th Oct 2011
If you mounted a drive out of someone's windows machine on your Linux system, would this script work to clean up file names on the ntfs partition?

The worst naming conventions I see are done by windows users.
0 Votes
+ -
Contributr
it should work
mfioretti 12th Oct 2011
pgit,
as far as I can tell, the script should work on every filesystem that Linux can read and write, it shouldn't matter which filesystem it is. Because it only changes _names_, that are supported on any file system, not permissions, links or other less universal stuff. This said, I have not had the possibility to try it on all the filesystems around.
0 Votes
+ -
I tried detox, and I tried this script.
(am I confused, or is harder than it ought to be to copy-paste? this isn't BASIC, so why are there line numbers?)

Someone sent me a tar.Z file that contained some bad files.

ls -b output here:
\177
\177\177\177\030\030\030\030
ls -l
1057 Oct 8 16:30 ?
1058 Oct 8 16:03 ???????

The script posted here just leaves them as is.

detox gives some odd graphics and says the files already exist.
Cannot rename lib/??? to lib/: file already exists
Cannot rename lib/????????????????????? to lib/: file already exists

I manually moved them with
mv ? one_bad_character
mv ??????[!c] seven_bad_characters
(because there happened to be another file with seven characters that ended in c)

--
clarence
0 Votes
+ -
Contributr
... it makes it easier for me to point to several parts of the scripts, but you must remove them if you cut and paste the script code above into a file ! Sorry that this wasn't clear.
0 Votes
+ -
Hi
I copied the code above, removed the line numbers and saved the file with the .sh extension.
I tried using it but can't get it to change any file names.
Could someone tell me how to run the script?
0 Votes
+ -
Contributr
what have you done exactly?
mfioretti Updated - 16th Jan 2012
Masarin,

have you realized that the code in this page doesn't change file names but only generates another file with the commands to change those names, and that is that second file that you must run?

This said, in general these are scripts that you must run from a linux command line, that is from the textual interface of programs like konsole or Gnome Terminal. You must run the script with the code in this page by giving to it the name of the top folder that contains the files and other folders you want to sanitize. For example, if that folder is /home/masarin /weirdfiles and you saved the code in a file called scriptname.sh, you should type a command like this at the prompt:

#> scriptname.sh /home/masarin/weirdfiles

you should also make the script executable first, with this other command:

#> chmod 755 scriptname.sh

this will generte what I called clean_tmp_files_2. and that is the file you must run to change names
If you have already done this, please describe with more details what is happening and pass some examples of file names that don't change

HTH,
Marco
0 Votes
+ -
"have you realized that the code in this page doesn't change file names but only generates another file with the commands to change those names, and that is that second file that you must run?"

Ok I got it now happy. I did not realize this.

Another q. do you run the commands in the second file (clean_tmp_files_2) one by one in the konsole window, or can you run them automatically?
0 Votes
+ -
Contributr
clean_tmp_files_2 is a list of commands. The way to execute them all at once is to type "source /tmp/clean_tmp_files_2" at the command prompt (or whatever else is the absolute path to that file)
Keyboard Shortcuts:
Prev
Next
Toggle
Join the conversation
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.