The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 05-17-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
You just need to escape or double quote the special characters on the command line. In my experience, Bash does this for you automatically with tab completion, although there are some minor glitches.

The only characters you absolutely cannot use in a file name are slash (because it's used to separate directories) and ASCII null (because it's used internally to terminate strings).

Here's a quick attempt at batch rename.

Code:
for f in *; do
  case $f in *[!A-Za-z0-9_-]*)  mv -i "$f" "`echo "$f" | tr " " _ | tr -dc A-Za-z0-9_-`";; esac
done
This might be even a little bit too conservative in what characters it will accept in a file name, but at least it's a start.