So, say I have a folder containing some 500 subfolders... all of these subfolders have a common string to their name... specifically, the names all start with a # sign.
Hypothetically, say I want to remove the # from the front of each and every one of these folder names.
Anyone know of a script that could perform this function? It can be bash, or php, or whatever... I honestly don't care, so long as it gets the # sign out of the front of the name.
Ideas?
Mass Renaming Of Folders
-
- Long Time Forum Regular
- Posts: 2813
- Joined: Sat Aug 20, 2005 9:30 am
- Location: The Netherlands
There's probably a million ways to do this, but I think this will work:
There are probably also specialized rename programs available. Use at your own risk. Run it in the parent directory of the dirs you want to fix.
(You could comment out the mv command first to see if this script will do exactly what you want it to do.)
Code: Select all
#!/bin/bash
#
# This script removes all hash signs (#) from the beginning of directories and files under the current working directory
for NAME in *; do
FIXEDNAME=`echo $NAME | sed 's/^\#//'`
if [ "$NAME" != "$FIXEDNAME" ]; then
echo "Renaming $NAME to $FIXEDNAME"
mv $NAME $FIXEDNAME
fi
done
(You could comment out the mv command first to see if this script will do exactly what you want it to do.)
Lemonbit Internet Dedicated Server Management
-
- Forum User
- Posts: 60
- Joined: Sun Dec 05, 2004 4:16 am