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
?
-
1difficult to understand, try using the blockquote or code sample to enter the file name or commands from body toolbar while drafting your question– BharatCommented Aug 10, 2018 at 21:00
-
Similar to stackoverflow.com/questions/6911301/… ...– AnonCommented Aug 11, 2018 at 3:20
Add a comment
|
2 Answers
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// /}"
else
echo "Replacement for '${file}' already exists; skipping"
fi
done
-
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. Commented Aug 11, 2018 at 6:50