Need Shell script to add prefix to multiple files' name.

Posted by viettechorg, 03-25-2007, 02:09 PM
Hello, Does anyone know any of the shell script(or something running on linux) that adds a prefix to multiple files(all files in 1 folder)? So instead of changing file name for each file, we need something that save time I've been trying to write one myself but it did not work. Also i tried to search no nothing found. I think this should be a handy script for many webmaster. So if anybody have this or know where to get this please share it here. Thank you

Posted by Barti1987, 03-25-2007, 02:28 PM
Here is something out of my mind (test before usage): Peace,

Posted by viettechorg, 03-25-2007, 02:49 PM
Thanks, i will give it a try

Posted by viettechorg, 03-25-2007, 06:40 PM
It does not work for me, it did not change file name or anything Any idea?

Posted by Slidey, 03-25-2007, 07:14 PM
easy: for x in `ls`; do NEWNAME=`AAAAA${x}`; mv "$x" "$NEWNAME"; done run it from the command line (bash/sh - will fail in ksh/csh/others) obviously replace AAAAA with whatever you want to prepend to each filename. It'll rename all files in the current directory, so if you want to be a bit more specific you'll need to play around with the ls

Posted by tanfwc, 03-25-2007, 11:41 PM
change the script given by azizny to

Posted by foobic, 03-26-2007, 12:05 AM
Hmm, whether e (file exists) or f (file is a regular file) that if statement will return false for all the files you want to rename. Perhaps azizny meant this: so the if statement prevents you from stomping on any existing file that happens to be named phpbb_otherfilename. Definitely get a solid backup before trying this at home

Posted by viettechorg, 03-26-2007, 12:56 AM
Works like a champ, thanks alot.

Ця відповідь Вам допомогла?

 Роздрукувати цю статтю

Також прочитайте

Changing File ext. to File

Posted by haleyhosting_com, 03-24-2007, 01:31 PMi have a site upithere.com . its a pretty popular...

Disk IO performance

Posted by diskio, 03-26-2008, 08:03 PMFrom the Disk I/O performance is it better 1) to have main...

How to retrieve the total number of rows when using LIMIT X, XXX

Posted by yangyang2036, 09-17-2008, 10:09 PMWith php+mysql, $results -> num_rows returns the...

how protection upload from members {jpg-gif-png} only ?

Posted by 3okl, 09-18-2008, 07:06 PMif member have none photo the uploader start upload anyfile...

Delete files created on a specific date

Posted by Acroplex, 06-28-2008, 08:16 PMIs there a quick shell command to find (inside a...