Starting to look like that a filename "cleaner" or validation checker could be handy. I won't even bet that old-polack has already spotted this years ago. I seem to remember he had a script to sort out the spaces in filenames. Since I am now saving files with spaces that would be handy.
Actually have a few; all being
variations on the
same basic script. The first replaces the
space with an
underscore;
---------------------------------------------- start ---------------------------------------------------
#!/bin/sh
# Author=old-polack
# Name=unspace
# Purpose=To replace spaces in file names with "_"
for i in *.*; do mv "$i" `echo $i | tr ' ' '_'`; done----------------------------------------------- end ---------------------------------------------------
This is basically the same script, but replaces the
space with a
dash;
------------------------------------------------ start --------------------------------------------------
#!/bin/sh
# Author=old-polack
# Name=unspace1
# Purpose=To replace spaces in file names with "-"
for i in *.*; do mv "$i" `echo $i | tr ' ' '-'`; done------------------------------------------------- end --------------------------------------------------
This one replaces
spaces with an
underscore in
directory names as well as
file names;
------------------------------------------------ start --------------------------------------------------
#!/bin/sh
# Author=old-polack
# Name=unspaceall
# Purpose=To replace spaces in both directory, and file names with "_"
for i in *; do mv "$i" `echo $i | tr ' ' '_'`; done------------------------------------------------- end --------------------------------------------------
This one replaces the spaces in
directory names and
file names in the
current directory and whatever
sub directories it contains;
------------------------------------------------ start --------------------------------------------------
#!/bin/bash
# Author=old-polack
# Name=deepspace
# Purpose=run unspaceall,
# then cd into each sub directory,
# run unspaceall, then return to the present directory.
unspaceall;
for i in */; do cd "$i" && unspaceall && cd ../; done------------------------------------------------- end --------------------------------------------------
If one has deeply
nested sub directories, burrow down to the next layer that still has spaces present and run the script again. Save each script, using the name shown in each, in
/home/<user>/bin which by default is already in your
<user> $PATH, then make each executable by right clicking each and choosing
Properties --> Permissions and then checking the
Is executable box.
Note: unspaceall replaces spaces with
underscores, but can be
edited to use
dashes if desired, as shown with
unspace1.