You have provided very little information, but assuming that you are doing this in bash and have a list of files whose prefix needs to be removed, you can pass the list through sed :
For example:
./generate_your_list_of_files | sed -e 's/^prefix//'
or if your file list is separated by spaces:
echo TD-file1 TD-file2.x.yt TD-file3-beep | sed -e 's/\<TD-//g'
The first matches the prefix at the beginning of the line and removes it. The second corresponds to TD- (or any other prefix that you want to replace) only when it occurs at the beginning of a word and replaces it in all matches on all lines. This can become dangerous, for example, for example, the file TD-file\ that\ TD-contains\ space.txt becomes file\ that\ contains\ space.txt
As an extra note, don't get a list of files with ls . This is a terrible mistake . If you need to get a list of files to work and links in more than one place, I would suggest putting them in an array:
files=(*)
and then work with this array.
Due to popular queries (one comment below), here's how to rename all files in a directory starting with XY TD- so that the prefix is removed (thanks @tripleee):
for file in prefix*; do mv "$file" "${file#XY TD-}" done
Shahbaz May 10 '12 at 2:26 p.m. 2012-05-10 14:26
source share