I have a file whose file name has a space like First Name_20180810.csv. The date (20180810 in the above example) changes daily in the filename. How can I rename First Name_*.csv to be FirstName_*.csv?

  • 1
    difficult to understand, try using the blockquote or code sample to enter the file name or commands from body toolbar while drafting your question
    – Bharat
    Aug 10, 2018 at 21:00
  • Similar to stackoverflow.com/questions/6911301/… ...
    – Anon
    Aug 11, 2018 at 3:20

2 Answers 2


If you do not have access to the rename tool, this should work:

for file in *.csv; do
    if ! [[ -f "${file// /}" ]]; then
        mv "$file" "${file// /}"
        echo "Replacement for '${file}' already exists; skipping"
  • I always recommend using mv -i or -n when doing any sort of bulk move/rename, to avoid silent and irreversible data loss in case there are any name conflicts. Aug 11, 2018 at 6:50

Use rename command:

rename "s/ //g" *.csv

man rename :examples

You must log in to answer this question.

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