LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 08-09-2006, 10:02 PM   #1
Geminias
Member
 
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, 10:28 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
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.
 
  


Reply


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 07:56 AM
Unix script : Append to a file linux_newbee Linux - Newbie 2 06-08-2006 02:12 PM
bash:output file names from shell script to vi sickboy Linux - Newbie 6 10-14-2004 04:40 AM
Help with a Script for Trimming last 2 letters of file names eagletech Linux - Newbie 3 11-13-2002 07:04 AM


All times are GMT -5. The time now is 10:31 AM.

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