Skip to content

September 30, 2009

Batch file and directory rename

I needed a quick way to go through a directory and rename some files and directories to remove a specific bit from the name. By using bash’s parameter expansion feature we can accomplish that in just a few lines.


#!/bin/bash
for i in *something* ; do
echo ${i/-*[something]}
mv $i ${i/-*[something]}
done

This takes all files and directories with something somewhere in their name, and strips it out.

Read more from Bash

Share your thoughts, post a comment.

(required)
(required)

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments