Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-09-2006, 09:02 PM   #1
Registered: Sep 2005
Posts: 201

Rep: Reputation: 30
Script to append to file names

Hey hackers, I just need to append a suffix to a bunch of files and there are too many to do it manually.

I need help writing a script to do this for me:

file1.php = file1.php.php //notice the extra .php
Old 08-09-2006, 09:28 PM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Are all of the files in the same directory?
How many files are there?

If there aren't too many files you could use a one-liner like:
for file in *.php; do mv "$file" "${file}.php"; done

If you are talking about thousands of files, the "*" wildcard will take up too much memory when expanding.
Then you need another approach, such as using find.
find ./ -maxdepth -type f -name "*.php" -exec mv '{}' '{}'.php \;
If you want to tranverse subdirectories, remove the "-maxdepth 1" argument.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
script to change file name and append the date john_551 Linux - Software 4 08-26-2006 06:56 AM
Unix script : Append to a file linux_newbee Linux - Newbie 2 06-08-2006 01:12 PM
bash:output file names from shell script to vi sickboy Linux - Newbie 6 10-14-2004 03:40 AM
Help with a Script for Trimming last 2 letters of file names eagletech Linux - Newbie 3 11-13-2002 06:04 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:19 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration