Novell is now a part of Micro Focus

Space Replace 1.0.1

Novell Cool Solutions: Cool Tool

Digg This - Slashdot This

In Brief

Script to replace all spaces in file and directory names in a given directory (even recursive if you want).


Updated:25 Jul 2005
File Size:2.1KB
Publisher:Richard van Kampen


Please read the note from our friends in legal before using this file.


Most p2p files (mp3, mpeg, docs) have spaces in their file names which Linux doesn't like very much. Let this script replace all spaces with underscores for you. This script can also commit changes to sub-directories.

Example: space -r /home/richard/mp3 replaces all spaces with underscores in all file and directory names in /home/richard/mp3, including all sub-directories.

For all Linux users.


version 1.0.1:

  • Name change: space is now called spacereplace.
  • Massive speed improvement: V1.0.1 is appr. 10 times faster than v1.0.0.
    V1.0.1 processes 1702 files in 56 sub-directories in less than 3 seconds on my AthlonXP 2400.
  • Fixed: spacereplace now handles special characters in file names without problems.
  • spacereplace without options now returns help. This is to avoid unintentional space replaces.


Comments: June 21, 2007 - Friedel Loinger

I downloaded spacereplace-1.0.1.tar.gz (publisher: Richard van Kampen) and installed it in our Linux system. This script should be able to replace all spaces in a file or directory name, but if fails if directories or filenames start with a dot (.). The bug is in the section 'function getdirs':

for i in $(echo */); do

The command 'echo */' does not show directories starting with a dot.

I replaced this line with the following one:

for i in $(find . -type d -mindepth 1 -maxdepth 1); do

It seems that it solved the problem.

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions.

© Copyright Micro Focus or one of its affiliates