LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-06-2006, 08:34 PM   #1
uthinkicare
LQ Newbie
 
Registered: Jun 2006
Posts: 8

Rep: Reputation: 0
automatically rename file


Hi, i understand that if u do a mv untest.txt /root/test , it will move untest.txt to test directory. But it i want it to automatically rename it to test.txt, how can i go about doing it by using shell script???

can anyone teach me or give mi some idea?

thanks in advance.
 
Old 12-06-2006, 08:39 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Have a look at man mv for different uses of the mv command, but basically:
Code:
#!/bin/sh
mv untest.txt /home/steve/test/test.txt
 
Old 12-06-2006, 08:49 PM   #3
uthinkicare
LQ Newbie
 
Registered: Jun 2006
Posts: 8

Original Poster
Rep: Reputation: 0
Hi, thanks for your reply.

There's 3 files, naming aaa.txt, bbb.txt, ccc.txt.

If i do a mv *.txt, all files in .txt extension will be moved over. If i want it to automatically rename all the files to 1-aaa.txt, 2-bbb.txt, 3-ccc.txt ............. after moving it, how should i go about doing it?


thanks in advance.
 
Old 12-06-2006, 09:14 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Do you mean something like this?
Code:
#!/bin/bash

(( n = 0 ))

for i in *txt; do
  (( n += 1 ))
  mv $i tmp/$n-$i
done
 
Old 12-06-2006, 10:28 PM   #5
uthinkicare
LQ Newbie
 
Registered: Jun 2006
Posts: 8

Original Poster
Rep: Reputation: 0
ops.. the .txt i should change to .png.... haha..sorry my mistake..

thanks alot..

Last edited by uthinkicare; 12-06-2006 at 10:29 PM.
 
Old 12-07-2006, 03:19 AM   #6
uthinkicare
LQ Newbie
 
Registered: Jun 2006
Posts: 8

Original Poster
Rep: Reputation: 0
erm.. sorry again. i think it will automatically sort it..

thanks again..

Last edited by uthinkicare; 12-07-2006 at 03:29 AM.
 
  


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
how to rename a file and copy a file in a shell zach014 Linux - Newbie 6 11-23-2006 09:23 AM
rename a file anoosh Programming 3 04-12-2006 02:15 PM
How can i Rename file? Khmer Linux - Newbie 4 10-21-2005 08:09 AM
program to rename mp3 automatically? buffed317 Linux - Software 1 02-22-2005 07:48 PM
How do I rename a file? Thaidog Linux - Newbie 5 10-10-2003 10:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:02 PM.

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