To programmatically rename N files, you can use a simple bash
for loop.
#!/bin/bash
set -eux
# find all your files by using a `grep` pattern
pattern="insert_filename_pattern_here" # you must enter your filename pattern here
# create an array of filenames and split on newlines
IFS=$'\n'
tmp=($(ls | grep ${pattern}))
unset IFS
# for each filename
for filename in "${tmp[@]}"; do
# rename the filename to use "_" character instead of a " " character
mv -v "${filename}" "${filename// /_}"
done
If you have less than 5 filenames, then you can manually type in all the filenames and use the rename
command like the above solution suggests. But for me... I prefer the programmatic solution... even when there is only 4 files.
p.s.
if you aren't familiar with Bash
's Parameter Expansion (i.e. ${filename// /_}
) you could use the rename
command:
if ((0)); then
mv -v "${filename}" "${filename// /_}"
else
rename ' ' '_' "${filename}"
fi
bash
for loop: see my solution here.