Trouble renaming files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Trouble renaming files
# 1  
Old 01-17-2006
Trouble renaming files

I am trying to add an temporary extension to the end of all files under a certain directory that contain a certain substring within their name. I've tried using a pipe by doing "ls -R -1|grep "*substring*"|mv -S a=.tmp . ." but realized that won't work because mv doesn't accept input from stdin and ls doesn't return the full path name of files. I then tried using find by doing "find . -name "*substring*" -exec mv -S a=.tmp {} . ';'" but using the period puts all the files the calling directory. I am running out of ideas on how to do this. Does anyone know a command to do this? Thanks

Last edited by VashTheStampede; 01-17-2006 at 02:18 PM..
# 2  
Old 01-17-2006
Start testing with something like this:
Code:
for file in `ls -R -1 *somestring*`
do
    mv "$file" "$file".tmp
done

# 3  
Old 01-17-2006
find . -name "*somestring*" | xargs -I {} mv {} {}.tmp
# 4  
Old 01-17-2006
Quote:
Originally Posted by mahendramahendr
find . -name "*somestring*" | xargs -I {} mv {} {}.tmp
Thanks, that seems to work but not quite the way I was hoping. The reason I was trying to use the -S option on the mv was because I have remove the .tmp extension immediately after running something else. This doesn't seem easily feasible though with your method. Is there a similar way to remove the .tmp?
# 5  
Old 01-17-2006
try this, if this is not what you wanted... can you post an example

find . -name "*somestring*" |sed 's/.tmp$//g' | xargs -I {} mv {}.tmp {}
# 6  
Old 01-18-2006
Quote:
Originally Posted by mahendramahendr
try this, if this is not what you wanted... can you post an example

find . -name "*somestring*" |sed 's/.tmp$//g' | xargs -I {} mv {}.tmp {}
Ah, genius! That is exactly what I was looking for. I have a lot to learn. Thanks for the help
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

2. UNIX for Dummies Questions & Answers

Trouble with deprecated files

I apologize if I am "over-posting" in this forum; I know little about this stuff and I have several software programs that I must install. I have found this forum to be extremely helpful. Anyways, I am trying to install ZThreads on my computer (Mac OS X 10.7.3). When I run "make" it returns with: ... (1 Reply)
Discussion started by: Tyler_92
1 Replies

3. UNIX for Dummies Questions & Answers

Renaming files

Hi all, I'm working in a specific directory and I have file names which I'd like to rename but in a way in which I can specify the new filenames as @ARGV or user input at prompt. Can someone shed some light on this? Cheers :) (7 Replies)
Discussion started by: pawannoel
7 Replies

4. Shell Programming and Scripting

renaming files or adding a name in the beginning of all files in a folder

Hi All I have a folder that contains hundreds of file with a names 3.msa 4.msa 21.msa 6.msa 345.msa 456.msa 98.msa ... ... ... I need rename each of this file by adding "core_" in the begiining of each file such as core_3.msa core_4.msa core_21.msa (4 Replies)
Discussion started by: Lucky Ali
4 Replies

5. UNIX for Advanced & Expert Users

renaming files

How can I rename files with .c to .cpp in my current directory and if any directory present in current directory system should descend in to that and checks ( find ).... tell me how to achieve this using find command and other if any? thanks. (7 Replies)
Discussion started by: shahnazurs
7 Replies

6. UNIX for Dummies Questions & Answers

Need help renaming files

I just can't figure this one out. I have a lot of files name (for example) ABC1234.5678.ext I need to rename these files U0105678PQRS So I'm removing everything before the first "." I'm keeping "5678" in the file name Adding "U010" to the front of "5678" Dropping the ".ext" extension ... (5 Replies)
Discussion started by: bbbngowc
5 Replies

7. UNIX for Dummies Questions & Answers

renaming files

I have a list of files named ab_*.csv I would like to remane them all by removing the ab_ and have *.csv I did the following but I am surely missing something. /* wrong script */ for i in `ls -1 ab_*`; do mv ab_$i $i; done Thanks in advance. (1 Reply)
Discussion started by: jxh461
1 Replies

8. Shell Programming and Scripting

Renaming the files

Hello, i wanna rename my files which names are written in movies.txt films.txt = amovie bmovie cmovie dmovie emovie and i wanna find this files and rename the files to 1_amovie ... (12 Replies)
Discussion started by: redbeard_06
12 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. UNIX for Dummies Questions & Answers

Help with renaming files

Anyone out there know how, in a one line UNIX Command, I could rename(mv) a file that contains variable string as part of its name. The variable string is the process instance number. For example, I'd like to be able to rename XX_XXXXX_nnnnn.pdf (where nnnnn is a number and its value depends on... (4 Replies)
Discussion started by: mc_cool_e
4 Replies
Login or Register to Ask a Question