Wade Preston Shearer wrote:
I have a directory full of directories that are all named in the
following manner:
#####_alpha_name
I need them renamed to just:
#####
Is there an easy way via the command line to truncate them to just the
first five characters (which would be just their ID number)?
This works for me, but is probably overkill:
for file in *; do
new_name=$(echo $file | sed 's/^\([0-9]\{5\}\).*/\1/')
echo Renaming "$file" to "$new_name"
mv -v "$file" "$new_name"
done
You can change the \{5\} to whatever number you want to indicate the
number of digits to capture in a row.
--Dave
/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/