files

count files in directory

find DIR_NAME -type f | wc -l

list all files

find . -type f -printf "%T@ %p\n" | sort -nr | cut -d\  -f2-

rename1

The shell can do this pretty easily (here assuming ksh93, zsh, bash, mksh, yash or (some builds of) busybox sh for the ${var//pattern/replacement} operator):

for file in *.doc *.mp3 *.wav *.txt
do
  mv -- "$file" "${file// /_}"
done
Change the *.doc ... glob to match whatever files you're interested in renaming.

To rename all of the files in the current directory that currently have spaces in their filenames:

for file in *' '*
do
  mv -- "$file" "${file// /_}"
done

You might also consider adding a "clobber" check:

for file in *' '*
do
  if [ -e "${file// /_}" ]
  then
    printf >&2 '%s\n' "Warning, skipping $file as the renamed version already exists"
    continue
  fi
  mv -- "$file" "${file// /_}"
done

Or use mv's -i option to prompt the user before overriding a file.The shell can do this pretty easily (here assuming ksh93, zsh, bash, mksh, yash or (some builds of) busybox sh for the ${var//pattern/replacement} operator):

for file in *.doc *.mp3 *.wav *.txt
do
  mv -- "$file" "${file// /_}"
done

Comments