renaming files globally


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting renaming files globally
# 1  
Old 08-09-2010
renaming files globally

I am attempting to use a shell script to append the string "AAA" to the beginning of over 400 files and I am just missing that little piece to finish.

I am still a newbie and I am still learning scripting. This is what I have so far:

Code:
#!/usr/bin/ksh


find /home/vedder191/AAA_revised -type f -name "*.pdf" | while read oldname
do
newname=`echo $oldname >> AAA <---- Knowing that this won't work
mv $oldname $newname
done

So basically I am trying to append the AAA to the beginning of the name of all pdf's in the AAA_revised directory.

Last edited by pludi; 08-09-2010 at 04:01 PM.. Reason: code tags, please...
# 2  
Old 08-09-2010
is this what your wanting?

Code:
oldname="my.pdf"
newname="AAA$oldname"

mv $oldname $newname

# 3  
Old 08-09-2010
Almost but it errors because it tries to append the "AAA" to the beginning of the entire directory. AAA/home/vedder191/AAA_revised cannot rename
# 4  
Old 08-09-2010
Code:
 
$ oldname=awk.man
$ ls -l $oldname
-rw-r--r--   1 rx4521   staff      14737 Jun 16 11:19 awk.man
$ ls -l AAA*
AAA*: No such file or directory
$ mv ${oldname} $(dirname ${oldname})/AAA$(basename ${oldname})
$ ls -l AAA*
-rw-r--r--   1 rx4521   staff      14737 Jun 16 11:19 AAAawk.man
$

# 5  
Old 08-09-2010
Code:
find /home/vedder191/AAA_revised -type f -name "*.pdf" | awk -F"/" '{printf "mv "$0" ";$NF="AAA"$NF;}1' OFS="/" | sh

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming Files

I have a directory with a long list of files. I want to change their names such that the first letter of the name of the author is capitalised. I have tried the following command and did not get what I require. rename 'y/....../....../' *.pdf 2007--nystrom--Diss.pdf... (1 Reply)
Discussion started by: Danette
1 Replies

2. 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

3. UNIX for Dummies Questions & Answers

Renaming Files With 2 .

Dear All expertise.. just wanna ask if there is a way on how to change the filename as per below sample:- filename:- cob120514093156.03.466926330 CCBS-CPMM_SEND_COB_120514_100549_3.rpt to convert to:- cob120514093156.03.466926330.bd (rename from cob120514093156.03.466926330) ... (17 Replies)
Discussion started by: yokomo
17 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. Shell Programming and Scripting

Renaming Files

Hi Alll, I have a script that we use on the servers to change the name of files that have spaces in the name: #!/bin/tcsh set n = 0 foreach f ( * ) echo $f | grep " " if ( $? == 0 ) then mv "$f" `echo $f | sed -e "s/ /_/g"` @ n += 1 endif end echo $n changed I need to write a... (2 Replies)
Discussion started by: abch624
2 Replies

6. UNIX for Dummies Questions & Answers

Renaming Files

Hi Alll, I have a script that we use on the servers to change the name of files that have spaces in the name: #!/bin/tcsh set n = 0 foreach f ( * ) echo $f | grep " " if ( $? == 0 ) then mv "$f" `echo $f | sed -e "s/ /_/g"` @ n += 1 endif end echo $n changed I need to write a... (2 Replies)
Discussion started by: abch624
2 Replies

7. UNIX for Dummies Questions & Answers

renaming the files

Hi All, Today I got a small problem while handling zipped files in PROD support. There are files in this format and I had to grep them reading some contents A.B.gz.C.D where A,B,C and D stand for variables (like FIRST.NAME.gz.MIDDLE.LAST). I know that these files are zipped files and If I... (1 Reply)
Discussion started by: adurga
1 Replies

8. UNIX for Dummies Questions & Answers

installing globally

where is the best location in a system to install software globally for users to use. asuming your the sys admin. i know it might not matter, but just wondering. (2 Replies)
Discussion started by: savage
2 Replies
Login or Register to Ask a Question