Skip to main content
deleted 3 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

With zsh:

autoload zmv # best in ~/.zshrc
zmv -n '**/*[[:space:]]' '${f%%[[:space:]]#}'

(remove -n for dry-run when happy)

Would remove trailing whitespace characters from the end of every non hidden file or directory. Add (#q/) to the pattern argument if you want to restrict to directories only. Or (#qD) to also process hidden file.

POSIXly, you can do something approaching with:

LC_ALL=C find . -depth -name '*[[:space:]]' -exec sh -xcx -c '
  for f do
    : mv -i "$f" "${f%"${f##*[![:space:]]}"}"
  done' sh {} +

(remove -x and : when happy).

That one is limited to ASCII whitespace characters.

With zsh:

autoload zmv # best in ~/.zshrc
zmv -n '**/*[[:space:]]' '${f%%[[:space:]]#}'

(remove -n for dry-run when happy)

Would remove trailing whitespace characters from the end of every non hidden file or directory. Add (#q/) to the pattern argument if you want to restrict to directories only. Or (#qD) to also process hidden file.

POSIXly, you can do something approaching with:

LC_ALL=C find . -depth -name '*[[:space:]]' -exec sh -xc '
  for f do
    : mv -i "$f" "${f%"${f##*[![:space:]]}"}"
  done' sh {} +

(remove : when happy).

That one is limited to ASCII whitespace characters.

With zsh:

autoload zmv # best in ~/.zshrc
zmv -n '**/*[[:space:]]' '${f%%[[:space:]]#}'

(remove -n for dry-run when happy)

Would remove trailing whitespace characters from the end of every non hidden file or directory. Add (#q/) to the pattern argument if you want to restrict to directories only. Or (#qD) to also process hidden file.

POSIXly, you can do something approaching with:

LC_ALL=C find . -depth -name '*[[:space:]]' -exec sh -x -c '
  for f do
    : mv -i "$f" "${f%"${f##*[![:space:]]}"}"
  done' sh {} +

(remove -x and : when happy).

That one is limited to ASCII whitespace characters.

deleted 3 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

With zsh:

autoload zmv # best in ~/.zshrc
zmv -n '**/*[[:space:]]' '${f%%[[:space:]]#}'

(remove -n for dry-run when happy)

Would remove trailing whitespace characters from the end of every non hidden file or directory. Add (#q/) to the pattern argument if you want to restrict to directories only. Or (#qD) to also process hidden file.

POSIXly, you can do something approaching with:

LC_ALLLC_ALL=C find . -depth -name '*[[:space:]]' -exec sh -cxc '
  for f do
    echo: mv -i "$f" "${f%"${f##*[![:space:]]}"}"
  done' sh {} +

(remove echo: when happy).

That one is limited to ASCII whitespace characters.

With zsh:

autoload zmv # best in ~/.zshrc
zmv -n '**/*[[:space:]]' '${f%%[[:space:]]#}'

(remove -n for dry-run when happy)

Would remove trailing whitespace characters from the end of every non hidden file or directory. Add (#q/) to the pattern argument if you want to restrict to directories only. Or (#qD) to also process hidden file.

POSIXly, you can do something approaching with:

LC_ALL find . -depth -name '*[[:space:]]' -exec sh -c '
  for f do
    echo mv -i "$f" "${f%"${f##*[![:space:]]}"}"
  done' sh {} +

(remove echo when happy).

That one is limited to ASCII whitespace characters.

With zsh:

autoload zmv # best in ~/.zshrc
zmv -n '**/*[[:space:]]' '${f%%[[:space:]]#}'

(remove -n for dry-run when happy)

Would remove trailing whitespace characters from the end of every non hidden file or directory. Add (#q/) to the pattern argument if you want to restrict to directories only. Or (#qD) to also process hidden file.

POSIXly, you can do something approaching with:

LC_ALL=C find . -depth -name '*[[:space:]]' -exec sh -xc '
  for f do
    : mv -i "$f" "${f%"${f##*[![:space:]]}"}"
  done' sh {} +

(remove : when happy).

That one is limited to ASCII whitespace characters.

Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

With zsh:

autoload zmv # best in ~/.zshrc
zmv -n '**/*[[:space:]]' '${f%%[[:space:]]#}'

(remove -n for dry-run when happy)

Would remove trailing whitespace characters from the end of every non hidden file or directory. Add (#q/) to the pattern argument if you want to restrict to directories only. Or (#qD) to also process hidden file.

POSIXly, you can do something approaching with:

LC_ALL find . -depth -name '*[[:space:]]' -exec sh -c '
  for f do
    echo mv -i "$f" "${f%"${f##*[![:space:]]}"}"
  done' sh {} +

(remove echo when happy).

That one is limited to ASCII whitespace characters.