![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Truncate multiple file extensions | prvnrk | Shell Programming and Scripting | 12 | 04-04-2008 11:20 AM |
| Truncate last <n> characters from a file | Gwailo88 | UNIX for Dummies Questions & Answers | 1 | 03-05-2008 12:52 AM |
| script for Gzip thousands of file | thepurple | SUN Solaris | 10 | 01-02-2008 06:39 AM |
| Truncate File contain | rinku | Shell Programming and Scripting | 2 | 05-30-2007 07:43 AM |
| how to truncate a large (8 GB) file | kotasateesh | Shell Programming and Scripting | 1 | 07-05-2006 02:57 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to truncate thousands of file names
Folder of e-mails in maildir format had been corrupted. Typical file name is 1246281161.6777.m21JH:2,S . The " :2,S prevents " copying to another device. How can I simply remove the last four characters?
|
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|