Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a bunch (about 10 gigs worth) of files that I need to copy from an external linux disk to a Windows machine. Unfortunately some file-names that contain the ":" character have got into this collection.

None of these colon files needs to be on the windows machine so I need a quick solution to zap or rename them.

What would you all recommend? (I'm assuming something like a bash / perl / python script in Linux. We don't have powershell on the Windows machine. )

share|improve this question
add comment

6 Answers 6

up vote 16 down vote accepted

Review the offending files.

find /path/to/files -name '*:*' -print

Delete the offending files.

find /path/to/files -name '*:*' -exec rm {} +

Rename the offending files with an underscore.

find /path/to/files -name '*:*' -exec rename ':' '_' {} +
share|improve this answer
    
+1 for the preview. A solution to rename the file by simply removing the colon would be great. –  Manuel Faux Jul 27 '09 at 11:25
    
this is great ... exactly what I needed, thanks –  interstar Jul 27 '09 at 11:36
    
For the rename command I get syntax error at (eval 1) line 1, near ":" –  Dennis Williamson Jul 27 '09 at 12:25
    
What version of rename do you have? It was tested from util-linux-ng 2.14.1. –  Dan Carley Jul 27 '09 at 12:41
2  
There's a different rename that takes a perl regex. so you'd want -exec rename 's/:/_/g' {} I think Redhat based distributions used one, and debian the other. –  davidsheldon Nov 12 '09 at 16:17
show 1 more comment

You can delete all the files by doing

rm *:*

in the directory on the Linux box.

That should delete all files containing the colon.

Or you can rename them using the rename command

rename 'y/(.*):(.*)/$1$2/' *

That will replace test:something to be testsomething

share|improve this answer
add comment

For a more efficient version of Dan C's delete some UNIX variants support:

find /path/to/files -name '*:*' -delete

this avoids the need to fork and exec /bin/rm for every single matching file.

This -delete option is present on MacOS X and on my FC11 system (with findutils-4.4.0). I don't know how long ago it was added to findutils.

share|improve this answer
    
+1: Good point :) –  Dan Carley Jul 27 '09 at 15:05
add comment

The easiest way may be to zip the whole structure, and unzip the file to the Windows disk. Unzip knows how to remap illegal characters.

Requires you have the disk space though :(

share|improve this answer
add comment

If you want to change the filenames in flight (not modifying the source directory), GNU tar has a --transform option.

tar cf - -C $SOURCE_DIR . --transform=s/:/_/g | tar xf - -C $DEST_DIR

You could also use the --exclude option to avoid those files.

tar cf - -C $SOURCE_DIR . --exclude='*:*' | tar xf - -C $DEST_DIR

I don't see the --transform option on the RHEL5 machines where I work, but I think it's pretty common otherwise.

share|improve this answer
add comment

Also,

mmv ";*:*" "#1#2#3"

or a similar command should do the trick as well. Run it with -nv first, just to see what will be moved to what, without actually modifying anything

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.