The UNIX and Linux Forums  

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 07-01-2009
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,763
Usually if there are characters in a filename that are metacharacters - they mean something to the shell - you can surround the filename with double quotes or single quotes (tic) and copy the file or rename it. To remove the last 4 chars in the filename means you have to feed it to the mv command. Which the same as feeding it to a cp command

Try something like this to rename the files:
Code:
#!/bin/bash
ls ./maildir |
while read filename
do
   len=${#filename}
   len=$(( $len - 4 ))
   printf "mv '%s'  '%s'" "${filename}"  "${filename:0:$len}"
done > tmp.sh
chmod +x tmp.sh
tmp.sh
TEST this first.