Wednesday, February 18, 2015

[LINUX_Newbies] Re: Removing cruft from file names & directories

 

On 18Feb2015 20:16, Emil Payne <ehspayne@yahoo.com> wrote:
>I have several files and directories with names like:
>06 - The Six Snubnosed Princessesæ¬鮦꯸āā఍ด✪⬾㹂䑣䵒啻坝悋慩沜桰玧煹綵箄
>装袒雚鎞ꋫyᰂ.mp3
>I want to get rid of all the junk in the names.
>Is there a utility, program, package, script, etc. that can do this
>recursively?

Personally, I would be inclined to use find and my frename script, like this
(example, untested):

cd your-directory-of-junk-names
find . -type f -print0 | xargs -0 frename 's/[^\w\s]+//g'

then repeat for directories, probably in depth first reversed order.

You can get frename here (use the "Raw" link at top right):

https://bitbucket.org/cameron_simpson/css/src/tip/bin/frename

Note: you will want to consider the definition of "junk" characters in the
regexp above. I've used [^\w\s] (non-"word", non-space), but you probably want
a somewhat wider set.

In fact, I would recommend a test run like this (untested):

find . -type f -print | sed 'h; s/[^\w\s]+//g; x; G; s/\n/ => /'

to print a report of what would be done.

When it says what you hope, then apply it to your directory tree.

For further safety, I would work in a link tree:

cp -ral your-directory-of-junk-names a-new-directory-name
cd a-new-directory-name
... rename everything in here ...

Then examine the new directory tree for correctness. When you finally have it
right, throw away your oriignal directory (or move it sideways) and move the
renamed new directory tree into its place.

Look up the -l option for "cp", quit useful for exercises like this.

Cheers,
Cameron Simpson <cs@zip.com.au>

A software engineering discussion from Perl-Porters:
Chip Salzenberg: The wise one has seen the calamity,
and has proceeded to hide himself.
- Ecclesiastes
Gurusamy Sarathy: He that observeth the wind shall not sow;
and he that regardeth the clouds shall not reap.

__._,_.___

Posted by: Cameron Simpson <cs@zip.com.au>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)
To unsubscribe from this list, please email LINUX_Newbies-unsubscribe@yahoogroups.com & you will be removed.

.

__,_._,___

No comments:

Post a Comment