Bash script to rename all files within a folder...

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Bash script to rename all files within a folder...
# 1  
Bash script to rename all files within a folder...


I don't have any experience with making scripts in bash. I need a simple script to rename all files in a folder to the format file1.avi, file2.avi, file3.avi, and so on.....

Please note that the original files have different filenames and different extensions. But they all need to be renamed into the above format.....

Thank you! Smilie
# 2  
One way:
cd ./directory
for fname in *
    mv $fname file${cnt}.avi
    cnt=$(( $cnt + 1 ))

# 3  
Awesome. That worked!

Thanks jim mcnamara. Smilie

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #720
Difficulty: Medium
Alan Minsky was an adviser on Stanley Kubrick's movie 2001: A Space Odyssey.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simply Bash Script to Confirm that there are 2 Files in Same Folder

Im looking for 2 Files -> *.WAV and *.wav with find . -name 'unavail.wav' -o -name 'unavail.WAV' I need to list the Folders that contains these 2 Files? Thx in advance (13 Replies)
Discussion started by: valdez
13 Replies

2. Shell Programming and Scripting

Bash script read specific value from files of an entire folder

Hello, I heva a problem creating a script that read specifc value from all the files of an entire folder I have a number of email files into a directory and i need to extrect from each file 2 specific values. After that i have to put them into a new file that looks like that: To: value1 ... (1 Reply)
Discussion started by: ahmenty
1 Replies

3. Shell Programming and Scripting

Been working since 25+ hrs: Bash Script to rename files supposedly direct but difficult to execute

:wall::wall::wall: Hi I have horrible script below, need help in renaming ls -l output into new filename format: Desired output: cp -pv original_path/.* newDirectory/owner_of_file.%dd%mm%y.file_extension.first_8_characters_of_original_filename localuser@localuser:~ vi... (3 Replies)
Discussion started by: wolf@=NK
3 Replies

4. UNIX for Dummies Questions & Answers

Bash script to execute a program to rename files

I just can't figure it out , so please just give me a pice of advise how to: The existing Linux program foo2bar takes as its only argument the name of a single foo file and converts it to an appropriately-named bar file. Provide a script that when executed will run foo2bar against all foo... (4 Replies)
Discussion started by: raymen
4 Replies

5. UNIX for Dummies Questions & Answers

Bash script to rename files in a directory

Dear friends, I have created a script to rename all files in a directory by appending the file name with username (who created the file), the date it was created. For example, "apple.doc" should be renamed to "johnFeb23apple.doc" where "john" is the owner and "Feb23" is file created date. It... (4 Replies)
Discussion started by: djsnifer
4 Replies

6. Shell Programming and Scripting

Bash script to sort files into folder according to a string in the filename

Hi all. I am very new to linux scripting and i have a task i can only solve with a script. I need to sort files base on the date string in their filenames and create a folder using the same date string then move the files to their respective folders. Scenario: Folder Path:... (1 Reply)
Discussion started by: ace47
1 Replies

7. Shell Programming and Scripting

sed to rename files in a folder - please help with script

Hello, I am new to shell scripting and stuck on renaming files in a folder. The files have the format chp01_00001.wav chp01_00002.wav .... chp02_00001.wav chp02_00002.wav .... but I want them to have the following names: chp_bloomy_00001.wav chp_bloomy_00002.wav chp_bloomy_00003.wav... (8 Replies)
Discussion started by: Bloomy
8 Replies

8. Shell Programming and Scripting

rename all the files in a folder..

Hi Guys, I have 5000 files in a folder. all are .DAT files. I want to rename them as .TXT files. I tried the following command. mv *.DAT *. TXT But it is throwing an error. Can you please tell me what am i doing wrong. Thanks & Regards, Magesh. (11 Replies)
Discussion started by: mac4rfree
11 Replies

9. UNIX for Dummies Questions & Answers

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... (4 Replies)
Discussion started by: tjmannonline
4 Replies

10. Shell Programming and Scripting

Hello - new here - bash script - need to rename and zip files.

I'm working on a project that basically unzips three zip files. When these unzip they create about 70+ directories with subdirectories of year/month with about 3 to 9 pdf files in each directory. Basically, I'm needing to figure out a way to zip these pdf files up. for instance the script... (1 Reply)
Discussion started by: Aixia
1 Replies

Featured Tech Videos