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



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 10: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 06:43 AM
how to truncate a large (8 GB) file kotasateesh Shell Programming and Scripting 1 07-05-2006 01:57 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-01-2009
steve900 steve900 is offline
Registered User
  
 

Join Date: Jul 2009
Location: Paris
Posts: 1
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?
  #2 (permalink)  
Old 07-01-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
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.
  #3 (permalink)  
Old 07-01-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 375
Code:
for i in *:*
do
mv $i `echo $i|cut -d":" -f1`
done
Run the below command separately
Code:
echo $i|cut -d":" -f1
to make sure you are getting what you want.
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 07:34 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0