Actions
Eliminazione file by ultimo carattere¶
Nel caso in cui il file termini con _ viene rinominato senza:
#! /bin/bash
# accept the root dir as first arg
root_dir=$1
# for each into this dir remove the final underscore
for entry in ${root_dir}/*
do
# get the last char
char=${entry: -1}
# print filename
echo "Check ${entry}"
# if the last char is an underscore remove it
if [ ${char} == "_" ]; then
# this trick returns the filename without the last char
filerena=${entry::-1}
echo "Renamed in ${filerena}"
mv "${entry}" "${filerena}"
fi
done
Updated by Gabor Murray over 6 years ago · 7 revisions