Home arrow Journal arrow Add a prefix to multiple files from a shell script
Add a prefix to multiple files from a shell script PDF
Friday, 20 April 2012
If you have multiple files in a directory and you want to add a prefix to each file automatically, you can do that with a simple shell script (/bin/sh).

Next example will add "05_" prefix to every .png image file name from curent directory and will save the new name in a newly created "renamed" directory:

rename.sh
#!/bin/sh

prefix="05_"

files=`ls *png`
mkdir renamed

for i in $files
do
  echo "Processing: "$i
  cp $i "renamed/"$prefix$i
done

Last Updated ( Wednesday, 25 April 2012 )
 
< Prev   Next >

Other BSD Systems

OpenBSD

Misc

Solaris

Polls

Best BSD firewall?