LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-04-2009, 11:47 AM   #1
v2010
Member
 
Registered: Feb 2005
Location: us
Posts: 98

Rep: Reputation: 15
Unhappy linux rename multiple files to same suffix


hi all

I do have mutliple files want to be renamed with same suffix.
for example

files start with 1ab, 1ac, 1ad ....
and want them to rename them with same suffix like 1ab.dum 1ac.dum 1ad.dum...

Is it any way to do that in linux with one command or script.

Other question is to
split the huge files with same suffix, I did used split command to split the file but it does not give me the suffix option.

Thanks appreciate your help

venkat
 
Old 06-04-2009, 11:50 AM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
For rename:
Code:
for filename in $(ls 1a*)
do
   echo "Renaming file: $filename to ${filename}.dum"
   # mv $filename ${filename}.dum
done
 
Old 06-05-2009, 12:54 PM   #3
v2010
Member
 
Registered: Feb 2005
Location: us
Posts: 98

Original Poster
Rep: Reputation: 15
Hi there

Thanks a lot, it works like a charm.

I do have one more help to ask,

I do have the 2000 files starting with random file prefix,
I would like to change the prefix like dum_1.x dum_2.x, dum_3.x
as a running numbers.

Please let me know how can I do that , really apprecite.

cheers
venkat
 
Old 06-05-2009, 04:45 PM   #4
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
I'm sorry, I don't entirely understand what your asking.

Please provide a sample list of five or six file names giving the before and after names that you are trying to achieve.

For example:
Code:
Before: dum_1.x
After : dum_0001.x
 
Old 06-05-2009, 05:05 PM   #5
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
Something like this?

Before:
teddy@lappy~/test$ ls
halabuda.x yoda.y.x yoyo.x.y

Code:
teddy@lappy~/test$ i=1; for filename in $(ls); do mv $filename $i.${filename##*.}; i=$((i+1)); done
After:
teddy@lappy~/test$ ls
1.x 2.x 3.y
 
Old 06-05-2009, 08:06 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Uncle_Theodore View Post

Code:
teddy@lappy~/test$ i=1; for filename in $(ls); do mv $filename $i.${filename##*.}; i=$((i+1)); done
Quote:
Originally Posted by Disillusionist View Post
For rename:
Code:
for filename in $(ls 1a*)
do
   echo "Renaming file: $filename to ${filename}.dum"
   # mv $filename ${filename}.dum
done
no need ls.. use shell expansion
Code:
for file in 1a*  #or for file in *
 
Old 06-05-2009, 08:07 PM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by v2010 View Post
Other question is to
split the huge files with same suffix, I did used split command to split the file but it does not give me the suffix option.

Thanks appreciate your help

venkat
check out csplit. man csplit for help
 
Old 06-05-2009, 08:15 PM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by v2010 View Post
I do have the 2000 files starting with random file prefix,
I would like to change the prefix like dum_1.x dum_2.x, dum_3.x
as a running numbers.
if you have Python, you can try the script in my sig called "File Renamer".
eg usage
Code:
# ls -1
XX_YY_010611.txt
XX_YY_010612.txt
XX_YY_010613.txt
XX_YY_010614.txt
log_0000118432_1.arc
log_0000118433_1.arc
log_0000118434_1.arc

# filerenamer.py -s  ".*" -e "dum_001:999.x" -l "*.*"
==>>>>  [ /test/images/log_0000118434_1.arc ]==>[ /test/images/dum_001.x ]
==>>>>  [ /test/images/log_0000118432_1.arc ]==>[ /test/images/dum_002.x ]
==>>>>  [ /test/images/XX_YY_010614.txt ]==>[ /test/images/dum_003.x ]
==>>>>  [ /test/images/XX_YY_010613.txt ]==>[ /test/images/dum_004.x ]
==>>>>  [ /test/images/XX_YY_010612.txt ]==>[ /test/images/dum_005.x ]
==>>>>  [ /test/images/log_0000118433_1.arc ]==>[ /test/images/dum_006.x ]
==>>>>  [ /test/images/XX_YY_010611.txt ]==>[ /test/images/dum_007.x ]
remove the "-l" option to commit changes
 
Old 06-06-2009, 08:07 AM   #9
v2010
Member
 
Registered: Feb 2005
Location: us
Posts: 98

Original Poster
Rep: Reputation: 15
Thanks a lot for the reply.

My problem is,

I do have the files

xxx.txt
x12.txt
x32.txt
xaaa.txt
x123c.txt
x3432a.txt

like variable prefix, I want to rename them entirely in prefix

I want something like this

mod_1.txt
mod-2.txt
mod_3.txt
....
.....
....
mod_100000.txt

I do have redhat5.

Thanks for everyone trying to help me out

venk
 
Old 06-06-2009, 10:28 AM   #10
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
why do you post the same question again without even trying ? what have you tried???
 
Old 06-06-2009, 10:36 AM   #11
amani
Senior Member
 
Registered: Jul 2006
Location: Kolkata, India
Distribution: Debian 64-bit GNU/Linux, Kubuntu64, Fedora QA, Slackware,
Posts: 2,766

Rep: Reputation: Disabled
use grename or krename
 
Old 06-10-2009, 12:09 AM   #12
v2010
Member
 
Registered: Feb 2005
Location: us
Posts: 98

Original Poster
Rep: Reputation: 15
Thanks a lot to every one. I did posted again because Disillunoist
need more details of what I need ?

I did tried other script, but it did not change the prefix the way I want. I did tried

$ i=1; for filename in $(ls); do mv $filename $i.${filename##*.}; i=$((i+1)); done

That changes the number but it did not replace the prefix the way I want. I am not good in python so not sure what I could change in that script for change the prefix.

Thanks a lot for the reply.

Again

I do have the files

xxx.txt
x12.txt
x32.txt
xaaa.txt
x123c.txt
x3432a.txt

like variable prefix, I want to rename them entirely in prefix

I want something like this

mod_1.txt
mod-2.txt
mod_3.txt
....
.....
....
mod_100000.txt



Here I did change the suffix with numbers for identification,

Thanks again for everyone trying to help me.
 
Old 06-10-2009, 12:54 AM   #13
rikxik
Member
 
Registered: Dec 2007
Posts: 88

Rep: Reputation: 19
Quote:
Originally Posted by ghostdog74 View Post
no need ls.. use shell expansion
Code:
for file in 1a*  #or for file in *
Another advantage is, in case of too many files, ls fails with error like "/usr/bin/ls: arg list too long" but shell expansion succeeds.
 
Old 06-10-2009, 01:06 AM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Code:
i=1
for filename in $(ls)
    do mv $filename mod_${i}.txt
    i=$((i+1))
done
See http://rute.2038bug.com/index.html.gz & http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
 
Old 06-10-2009, 03:28 AM   #15
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Code:
i=1
for filename in *.txt
do
   mv $filename mod_${i}.txt
   i=$(expr $i + 1)
done
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Bash Script - Rename Multiple Files embsupafly Programming 16 04-02-2010 03:50 AM
LXer: Rename multiple files to another extension in Linux LXer Syndicated Linux News 0 08-19-2007 03:10 PM
How to rename multiple files with the same extension rogueeve Linux - Newbie 3 05-18-2007 01:54 AM
Rename multiple files in folders??? adds2one Linux - Software 19 10-05-2006 12:22 AM
How to rename multiple files? Rostfrei Linux - Newbie 3 07-11-2006 06:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration