Last active
October 22, 2023 01:11
-
-
Save jaalorsa517/e990989882fe2ba648483f0027296d67 to your computer and use it in GitHub Desktop.
Rename list files, when deleted something characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
dirpath=/home/jaalorsa/Descargas | |
pattern="y2mate.com - " | |
echo "[INFO] INICIANDO SCRIPT" | |
echo "[INFO] OBTENIENDO NOMBRES DESDE PATH $dirpath" | |
# Obtener la lista de archivos utilizando el comando ls | |
files=$(ls $dirpath) | |
# Divide la variable en un array | |
IFS=$'\n' read -d '' -ra lista_archivos <<< "$files" | |
# Iterar sobre cada archivo en la lista | |
for archivo in "${lista_archivos[@]}"; do | |
echo "[INFO] BUSCANDO PATTERN $pattern" | |
# Comprobar si el archivo contiene el patrón que queremos eliminar | |
if [[ "$archivo" == *"$pattern"* ]]; then | |
echo "[INFO] RENOMBRANDO ARCHIVO $archivo" | |
# Obtener el nuevo nombre del archivo sin el patrón | |
nuevo_nombre=$(echo "$archivo" | sed "s/$pattern//") | |
# Renombrar el archivo | |
mv "$dirpath/$archivo" "$dirpath/$nuevo_nombre" | |
fi | |
done | |
echo "FIN SCRIPT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment