I have hundreds of files in a folder named transactions 1.csv, transactions 2.csv, transactions 3.csv etc

How do i remove the space in the file names, so they become transactions1.csv,transactions2.csv,transactions3.csv etc

Any help is appreciated?

1 Answer 1


With bash (and probably others) you can use ${f// /} to remove all spaces from $f:

for f in *.csv; do
    mv "$f" "${f// /}"

Also have a look at rename

rename ' ' '' *

but this only removes the first space, so it has to be applied several times.

  • @anonranger If this answer solved your issue, please take a moment and accept it by clicking on the check mark to the left. That will mark the question as answered and is the way thanks are expressed on the Stack Exchange sites.
    – terdon
    Sep 5, 2015 at 14:19
  • @Thomas Erker - What web resource/book you recommend on learning about bash programming?
    – anonranger
    Sep 7, 2015 at 15:58
  • @anonranger Sorry, can't really recommend anything. The Bash and sed & awk books from oreilly.com might be useful, but I haven't looked in them. Sep 7, 2015 at 21:16
  • 1
    rename can remove all the spaces: rename "s/ //g" * or "s/ /_/g" etc.
    – tedder42
    Jan 21, 2019 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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