Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I do a mistake when trying to move files from one location to another. Now all files are moved, but there is a * concatenated at the end of all names.

How do I remove all *s from end of file names in command line?

Note: I'm working with an embedded system, there is not any Internet connection. Please provide solutions with no need to install new stuff.

Thanks in advance

share|improve this question
up vote 5 down vote accepted

There is a command called (in an excess of originality) rename, that allows you to rename files using regular expressions.

In this case, you probably want to do:

rename 's/\*//' files...

Which will remove the first * character found in each filename.

You can use rename -n to list the renames that will be performed without actually doing them if you're worried about the regex not being correct.

share|improve this answer
This will replace every * anywhere in a file name (not only at the end). s/\\*$// or 's/\*$//' would probably work better. – Silke Aug 13 '12 at 12:10

Ubuntu comes with the rename command which can rename files by regular expressions.

If all your files are located in the same folder, you can simply do the following:

rename s/\\*$// *

(\\* is an escaped *, $ is the end of the file name. A match will be replaced with nothing.)

If all your files are in a directory structure, you can use find:

find / -exec rename s/\\*$// {} \;

Which executes rename /\\*$// on every file and directory on you system. Feel free to change the / to the folder in which the directory structure is located.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.