Skip to main content
added 25 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
for name in *\[*\]\ -\ *; do
  if [[ -d "$name" ]] && [[ ! -e "${name#* - }" ]]; then
    mv "$name" "${name#* - }"
  fi
done

The loop above, which would work in bash or ksh93 at least, gesgoes through all thingsnames in the current directory matching the filename globbing pattern *\[*\]\ -\ * (the brackets and spaces need to be escaped from the shell) and tests to make sure it's a directory and that the modified name doesn't already exist. If that's all ok, then it renames the directory.

The parameter expansion ${name#* - } will take the value of the variable name and remove everything from the start of it to the first occurrence of ␣-␣ (space-dash-space).

for name in *\[*\]\ -\ *; do
  if [[ -d "$name" ]] && [[ ! -e "${name#* - }" ]]; then
    mv "$name" "${name#* - }"
  fi
done

The loop above, which would work in bash or ksh93 at least, ges through all things matching the filename globbing pattern *\[*\]\ -\ * (the brackets and spaces need to be escaped from the shell) and tests to make sure it's a directory and that the modified name doesn't already exist. If that's all ok, then it renames the directory.

The parameter expansion ${name#* - } will take the value of the variable name and remove everything from the start of it to the first occurrence of ␣-␣ (space-dash-space).

for name in *\[*\]\ -\ *; do
  if [[ -d "$name" ]] && [[ ! -e "${name#* - }" ]]; then
    mv "$name" "${name#* - }"
  fi
done

The loop above, which would work in bash or ksh93 at least, goes through all names in the current directory matching the filename globbing pattern *\[*\]\ -\ * (the brackets and spaces need to be escaped from the shell) and tests to make sure it's a directory and that the modified name doesn't already exist. If that's all ok, then it renames the directory.

The parameter expansion ${name#* - } will take the value of the variable name and remove everything from the start of it to the first occurrence of ␣-␣ (space-dash-space).

added 15 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
for name in *Directory*\[*\]\ -Subject*;\ *; do
  if [[ -d "$name" ]] && [[ ! -e "${name##*name#* - }" ]]; then
    mv "$name" "${name##*name#* - }"
  fi
done

The loop above, which would work in bash or ksh93 at least, ges through all things matching the filename globbing pattern *Directory*\[*\]\ -Subject*\ * (the brackets and spaces need to be escaped from the shell) and tests to make sure it's a directory and that the modified name doesn't already exist. If that's all ok, then it renames the directory.

The parameter expansion ${name##*name#* - } will take the value of the variable name and remove everything from the start of it to the last space characterfirst occurrence of ␣-␣ (space-dash-space).

for name in *Directory-Subject*; do
  if [[ -d "$name" ]] && [[ ! -e "${name##* }" ]]; then
    mv "$name" "${name##* }"
  fi
done

The loop above, which would work in bash or ksh93 at least, ges through all things matching the filename globbing pattern *Directory-Subject* and tests to make sure it's a directory and that the modified name doesn't already exist. If that's all ok, then it renames the directory.

The parameter expansion ${name##* } will take the value of the variable name and remove everything from the start of it to the last space character.

for name in *\[*\]\ -\ *; do
  if [[ -d "$name" ]] && [[ ! -e "${name#* - }" ]]; then
    mv "$name" "${name#* - }"
  fi
done

The loop above, which would work in bash or ksh93 at least, ges through all things matching the filename globbing pattern *\[*\]\ -\ * (the brackets and spaces need to be escaped from the shell) and tests to make sure it's a directory and that the modified name doesn't already exist. If that's all ok, then it renames the directory.

The parameter expansion ${name#* - } will take the value of the variable name and remove everything from the start of it to the first occurrence of ␣-␣ (space-dash-space).

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

for name in *Directory-Subject*; do
  if [[ -d "$name" ]] && [[ ! -e "${name##* }" ]]; then
    mv "$name" "${name##* }"
  fi
done

The loop above, which would work in bash or ksh93 at least, ges through all things matching the filename globbing pattern *Directory-Subject* and tests to make sure it's a directory and that the modified name doesn't already exist. If that's all ok, then it renames the directory.

The parameter expansion ${name##* } will take the value of the variable name and remove everything from the start of it to the last space character.