首页 > 解决方案 > Remove prefix from a LIST of files in 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?

标签: linuxbash

解决方案


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.".


推荐阅读