Renaming Issue..


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Renaming Issue..
# 1  
Old 06-04-2009
Renaming Issue..

Hi guys..

Please help me.. I am a newbie to Unix..

How to change the extension of all .txt files in my current directory and also subdirectories to .my extension all together??

Regards,

Mahesh..
# 2  
Old 06-04-2009
The mmv command, if you have it, can rename the files in this fashion, but ordinary shell globbing cannot. For mmv you have to be careful to quote the strings to prevent the shell thinking its a glob.

Code:
mmv '*.txt' '#1.my'

Changing subdirectories is a bit tougher, since name matching cannot tell you what a directory is. So find will find all directories in the current directory, and feed them into a loop that renames them one by one.

Code:
find ./ -type d -maxdepth 1 -mindepth 1 | while read DIR ; do mv "$DIR" "$DIR.my" ; done

# 3  
Old 06-04-2009
I think he meant rename files including those in the subdirectories, not rename the subdirectories.

The general process is still the same as the one posted

In bash/Korn
Code:
find . -type f -name "*.txt" | while read file ; do mv "$file" "${file%%.txt}.my" ; done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

2. UNIX for Dummies Questions & Answers

renaming a file

Hi I remember i have create a file "Dechistory" before a month. But i dont remember exact location. I know i need to find out first that fiiles exact location for renaming it .......but i waant to that without going on that location.......how to do that ??? (1 Reply)
Discussion started by: tusharjoshi
1 Replies

3. Shell Programming and Scripting

Renaming files

Can someone please help. Much appreciated!! I have 4 directories, for ex... /RUN1/ReportTable.nxt /RUN2/ReportTable.nxt /RUN3/ReportTable.nxt /RUN4/ReportTable.nxt I would like to write a for loop, to add the directory name to each ReportTable.nxt I would like for it to be: ... (5 Replies)
Discussion started by: dirttysoufff
5 Replies

4. Red Hat

Cron issue while renaming a username

Hi All; I have a to rename a user account example User1 to User2 keeping everything same. Now I would be using usermod -l User1 User2 .However User1 has some cron jobs and by using the conventional usermod iam unable to transfer those cron jobs to User2 i.e after renaming the user. ... (4 Replies)
Discussion started by: maverick_here
4 Replies

5. Shell Programming and Scripting

Issue with File Renaming

I am trying to perform some validations on the source files. the script has file name pattern as an argument.The Input file has Single quotes in the filename . I want to remove those single quotes and split the file into 2 parts. below is my code FILE_NAME=$1 if then echo "\n Files are... (5 Replies)
Discussion started by: dsshishya
5 Replies

6. UNIX for Dummies Questions & Answers

renaming

Hi, I wrote a script to rename all files in a directory from uppercase to lowercase and changing spaces to underscores: #!/bin/sh echo "rename" read pathname cd $pathname for f in `ls "$pathname"` ; # listing directory for all files do echo... (1 Reply)
Discussion started by: the.noob
1 Replies

7. Shell Programming and Scripting

renaming files, please help

I want to rename the files by taking part of the file and appending date to it. please help e.g. abc-390.csv xyz-908.csv desired format is abc_YYYYMMDD.csv This is what I have but it is not working for each in *.csv; do mv $each /abc/data/"`date '+test_%Y%M%M'`".csv done (2 Replies)
Discussion started by: mqasim
2 Replies

8. Shell Programming and Scripting

Unix Arithmatic operation issue , datatype issue

Hi, I have a shell scripting. This will take 7 digit number in each line and add 7 digit number with next subsequent lines ( normal addition ). Eg: 0000001 0000220 0001235 0000022 0000023 ........... ......... ........ Like this i am having around 1500000 records. After adding... (23 Replies)
Discussion started by: thambi
23 Replies

9. Shell Programming and Scripting

renaming Files

Renaming Files more than 1000 in Diffrent Directories in system.. help me in this issue to resolve.... (5 Replies)
Discussion started by: sunsap
5 Replies

10. Shell Programming and Scripting

Renaming files

Hello. Need to rename 1000's of files with names like 991%20(2003)%20-%20991%20Ryall%20Prison%20Population%20and%20Recorded%20Crime.doc All I need is the beginning numbers , in this case 991 . Tried: for file in * ; do mv $file `echo $file | sed '/^{p;q}'` ; done but no luck. Thank... (8 Replies)
Discussion started by: whatsup
8 Replies
Login or Register to Ask a Question