Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove prefix from a LIST of files in bash [duplicate]

Tags:

linux

bash

I have a list of files with a common name pattern, all with the same structure (prefix ave.):

ave.20050716-12:00:00.stat_profiles.nc 
ave.20050816-12:00:00.stat_profiles.nc  
ave.20081116-00:00:00.stat_profiles.nc  
ave.20120215-12:00:00.stat_profiles.nc
ave.19990316-12:00:00.stat_profiles.nc  
ave.20020616-00:00:00.stat_profiles.nc  

My question is: How do I remove ave. from all the files in a file list / folder?

like image 517
PEBKAC Avatar asked Oct 16 '25 22:10

PEBKAC


1 Answers

You can use a for loop and string substitution

for file in ave.*
do 
    mv "$file" "${file#ave.}"
done

This is just an example to get you started and you should check for things such as already existing files with the name without "ave.".

like image 188
Alex M Avatar answered Oct 19 '25 13:10

Alex M