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
script for Finding files in a folder and copying to another folder satish2712 Shell Programming and Scripting 5 09-11-2008 04:07 PM
Auto copy for files from folder to folder upon instant writing Bashar UNIX for Advanced & Expert Users 2 08-21-2008 02:44 PM
Moving Files from one folder to another folder farooqpervaiz Shell Programming and Scripting 10 08-07-2008 02:20 AM
rename files help piltrafa UNIX for Dummies Questions & Answers 2 10-04-2007 09:47 AM
How to rename files? CompuTelSystem UNIX for Dummies Questions & Answers 9 05-14-2002 03:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-17-2008
tjmannonline tjmannonline is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 91
rename files in a folder

i have a folder that contains 100's of files: abc, bca, def, ghi....

i want to rename abc with 1, bca with 2, def with 3, ghi with 4 and so on.

my way, i create a file.txt with contents:
1
2
3
4
i use while loop to rename my files. without using file.txt, i just want to rename abc with 1, and then bca with 2 by incremental.
  #2 (permalink)  
Old 11-17-2008
wempy's Avatar
wempy wempy is offline
Registered User
  
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 208
Untested. Assumes that you want to rename the files as found alphabetically in the way that ls will output them.
Code:
NUM=1
ls |while read FN
do
mv $FN $NUM
$(( NUM + 1 ))
done

Last edited by wempy; 11-17-2008 at 06:37 AM.. Reason: corrected syntax
  #3 (permalink)  
Old 11-17-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink The following will help with the numbering

Code:
>ls -l | grep "^-" | cat -n | awk '{print $1","$10}'
That will output a numbered list of files from the directory.
1,afile
2,bfile

etc...
Then just create a loop to read through the output, renaming the second variable to the first.
  #4 (permalink)  
Old 11-17-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 592
Try:
Code:
ls -1 | cat -n | awk '{ system("mv "$2" "$1"");}'
  #5 (permalink)  
Old 11-17-2008
tjmannonline tjmannonline is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 91
this code works: ls -1 | cat -n | awk '{ system("mv "$2" "$1"");}'

is it possible to keep .mp3

example:

rename a to 1.mp3
rename b to 2.mp3
Closed Thread

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:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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