How can I remove blank spaces from files and folders names, but just at the beginning and at the end of the files and folders names?



2 Answers 2


There are apps that do this but I am not endorsing anything. In my experience, these apps save me hours, if not days, of work as often I need to rename or clean up thousands of images being imported from a camera.

Try searching for something like: Finder, Better, Rename.

Other than that -- you may have to write an AppleScript. There may be an AppleScript already out there. Search for AppleScripts, too.


maybe some thing like this to remove space from start of files:

for name in ; do mv -v -- "$name" "${name# }"; done 

maybe some thing like this to remove space from end of files:

for name in *; do mv -v -- "$name" "${name#% }"; done 

uses for loop with parameter expansion http://mywiki.wooledge.org/BashGuide/Parameters#Parameter_Expansion http://mywiki.wooledge.org/BashFAQ/073

  • 1
    You should always use the -i or -n option to mv when doing any automated move/rename operation like this -- without one of those options, mv will silently delete any files with conflicting names (and if there are bugs in the script, that could be a lot of files). Aug 4 at 19:15
  • Fair Point. Depends what you are trying to do. Adjust your flags accordingly. linux.die.net/man/1/mv . Manually checking every file can be arduous.
    – Daniel
    Aug 7 at 11:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .