How to rename all files at a time by appending some characters at the begining?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to rename all files at a time by appending some characters at the begining?
# 1  
Old 05-21-2015
How to rename all files at a time by appending some characters at the begining?

Hi

I have a list a filename in a directory starting with particular pattern
for example:
Code:
abc_1234.txt
abc_7565.txt
abc_7676.txt
abc_7765.txt

i need to rename all these files by appending bck. or bck_

Expected output:
Code:
bck.abc_1234.txt
bck.abc_7565.txt
bck.abc_7676.txt
bck.abc_7765.txt

Can anyone suggest something regarding this.
I tried the below code but its not actually working. How to make this permanent.

Code:
ls -1 abc* | awk '{$1="bck."$1; print $1}'

but not getting the expected result.

I am using k-shell

Last edited by Don Cragun; 05-21-2015 at 02:42 PM.. Reason: Change ICODE tags to CODE tags.
# 2  
Old 05-21-2015
Hiya

Try:
Code:
for f in abc*
do   mv "$f" "${f/abc/bck.abc}"
done

Or even simpler:
Code:
for f in abc*
do   mv "$f" "bck.$f
done

hth
This User Gave Thanks to sea For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Rename File Name with Special Characters

I am trying to rename files with spaces and other characters and not able to be successful. FileNames: UPLOAD REFERENCE.xls UPLOAD MASS REFERENCE.XLS find /UPLOAD REFERENCE/ -depth -type f -name "* *" -exec rename " " "_" "{}" ";" The above one is successful to replace spaces... (1 Reply)
Discussion started by: eskay
1 Replies

2. Shell Programming and Scripting

Rename directory removing last characters

Hello - I was looking to write a simple script trying to rename sub-directories chopping off the last n characters. For example: In /home/myname/dir there are three sub-directories: directory1_1, directory2_2, and directory3_3. Is there a simple script to chop off the last... (4 Replies)
Discussion started by: twckfa16
4 Replies

3. Shell Programming and Scripting

Copying multiple files and appending time stamp before file extension

Hi, I have multiple files that read: Asa.txt Bad.txt Gnu.txt And I want to rename them using awk to Asa_ddmmyytt.txt and so on ... If there is a single command or more efficient executable please share! Thanks! (4 Replies)
Discussion started by: Jesshelle David
4 Replies

4. Shell Programming and Scripting

Rename all files at a time

i have some bar files in a directory appp1.APP.RTP.DEV1 appp2.APP.RTP.DEV1 appp3.APP.RTP.DEV1 need to be renamed as appp1.APP.mmk.DEV1 appp2.APP.mmk.DEV1 appp3.APP.mmk.DEV1 i need to rename all files at a time. (6 Replies)
Discussion started by: saurau
6 Replies

5. Shell Programming and Scripting

Filename rename with characters of file

Hi, I need a bit of help. I've used awk to get the first 7 characters of a file - awk '{print substr($0,0,7)}' test.csv How do I now take this variable to rename test.csv to variable.csv ? Any help or advice would be greatly appreciated! (2 Replies)
Discussion started by: sianm
2 Replies

6. UNIX for Dummies Questions & Answers

Rename multiple files, changing prefix, extension and dropping characters

I'm currently only able to perform some very basic functions, so hope this makes sense... I have a set of about 27 files that need to be renamed from something like this: 000012ABCDEFGHIJ.XXX.YYY.ZZZ 000078KLMNO.XXX.YYY.ZZZ 000099PQ.XXX.YYY.ZZZ to something like this: newa012.abc... (11 Replies)
Discussion started by: bbmcg
11 Replies

7. Shell Programming and Scripting

Appending number of lines in the file to begining of the file

I am having 6 files named file1,file2....file6 and i need to append number of lines in each file to begining of the file. For example, If file 1 contains a b c d then after adding new line file1 should contain 4 a b c d Thanks in advance. (2 Replies)
Discussion started by: akhay_ms
2 Replies

8. UNIX for Advanced & Expert Users

junk characters in the begining of every line

Hi Experts, here is a background to my problem : I am exporting data from teradata using fastexport utility, as varchar data. This pads additional two bytes (2 places as seen in notepad) in the resultset. I have found out other means of avoiding it but can't use varchar option in that... (5 Replies)
Discussion started by: sumoka
5 Replies

9. Shell Programming and Scripting

Rename files and directories with special characters

Hello guys, I was looking for a shell script that removes all the special characters from the files and the subdirectories recursively. I could not locate it any more. Dose any body have a similar script that dose that? Thanks for the help. AV (0 Replies)
Discussion started by: avatar_007
0 Replies

10. Linux

rename files in a folder with date&time stamp

Hi, I want to rename all the files (more than 100 files) in a fodler to another folder with date&time stamp. foe eg, file1.dat file2.dat file3.dat .. to be renamed as file1100629_16_30_15.txt (yy-mon-dd_hh_mi_ss) file1100629_16_30_16.txt .. so on (2 Replies)
Discussion started by: feroz
2 Replies
Login or Register to Ask a Question