[Linux-disciples] Deleting the first couple of characters of a
file name.
Stephen R Laniel
steve at laniels.org
Fri Feb 10 11:54:55 EST 2006
On Fri, Feb 10, 2006 at 10:52:04AM -0600, Karl Sokol wrote:
> I have on my computer a number of songs that begin with the track numbers from
> the c.d. that they were from. I want to delete these numbers.
>
> If i move them all to a single folder, is there a way of deleting the first two
> characters on a bulk of files?
> Better yet, is there a way of deleting the first two characters only if they
> are numbers, thereby saving me from moving them at all?
This is why god invented the 'rename' tool. This command
will take all the files in a directory called 'foo' and
delete the first 2 characters, only if they are numbers:
rename 's/^\d{1,2}//' foo/*
Actually, that will delete anywhere between one and two
leading digits. To delete only two leading digits, do
rename 's/^\d{2}//' foo/*
To find every file in every subdirectory of foo and delete
leading digits, do
find foo -type f -exec rename 's/^\d{2}//' '{}' \;
--
Stephen R. Laniel
steve at laniels.org
+(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20060210/16675a21/attachment.pgp
More information about the Linux-disciples
mailing list