Eliminar los espacios de un directorio

By 6 de agosto de 2006 Linux No Comments

tux_topic_clean.pngComo eliminar los "espacios" y sustituirlos por "_"?

# for i in *; do mv -v "$i" $(echo "$i" | tr " " "_"); done

La forma cuidadosa de esto viene detallada en el siguiente script:

#! /bin/bash

# blank-rename.sh

# # Substitutes underscores for blanks in all the filenames in a directory.  ONE=1

# For getting singular/plural right (see below). number=0

# Keeps track of how many files actually renamed. FOUND=0

# Successful return value.  for filename in *

#Traverse all files in directory. do echo "$filename" | grep -q " "

#  Check whether filename if [ $? -eq $FOUND ]

#+ contains space(s). then fname=$filename

# Strip off path. n=`echo $fname | sed -e "s/ /_/g"`

# Substitute underscore for blank. mv "$fname" "$n"

# Do the actual renaming. let "number += 1" fi done  if [ "$number" -eq "$ONE" ]

# For correct grammar. then echo "$number file renamed." else echo "$number files renamed." fi  exit 0 

Leave a Reply

Your email address will not be published.