----- Original Message ----- From: "Rogan Creswick" <[email protected]> To: "Rich Shepard" <[email protected]>, "General Linux/UNIX discussion and help, civil and on-topic" <[email protected]> Cc: [email protected] Sent: Sunday, April 17, 2011 5:00:52 PM Subject: Re: [PLUG] Mass Removal of White Space in File Names
On Sun, Apr 17, 2011 at 4:44 PM, Rich Shepard <[email protected]> wrote: > I have two directories of images where each file name has spaces between > the words. I'm not having success writing a shell script that takes each > name in sequence, removes the white spaces, and leaves the extension as-is. > I'm certain that this can be done in perl, python, ruby, scheme, awk, sed, > and so on. I believe that a shell script would be a one-liner. There is as perl script called 'rename' that makes this very easy: $ rename 's/ //g' Some\ File\ Name.ext Will take the spaces out (destructively, so be careful. I don't know how it handles filename conflicts that may arise, I suspect not gracefully.). Combined with find and xargs, you can apply it to a whole directory tree (I haven't tested the following line though, so beware of typos/etc..): $ find <path> -type f | xargs rename 's/ //g' On debian my debian system, 'rename' is a symlink to /etc/alternatives/rename, which points to /usr/bin/prename, which apt-file says came with perl. If you don't have 'rename', try 'prename'. There are also probably other programs called rename. This is what I get if I run 'rename' with no arguments: $ rename Usage: rename [-v] [-n] [-f] perlexpr [filenames] --Rogan Be careful, rename on Ubuntu is different that that on OpenSuSE. The command line above with an expression is an OpenSuSE style command. Also be aware of spaces in directories that are parents of the target file. I'll post a perl script I wrote to deal with this as soon as I am in front of that machine. _______________________________________________ PLUG mailing list [email protected] http://lists.pdxlinux.org/mailman/listinfo/plug
