Bash code snippets

Updated: 2023-02-24
1 min read
[Linux Bash]

On This Page

Rename all files by pattern in current directory

files=(*)

# Loop through all files
for file in "${files[@]}"
do
  # Check if the file name contains the "№" symbol
  if [[ $file == *"№"* ]]; then
    # Remove everything before and including the "№" symbol
    new_file=${file##*"№"}
    mv "$file" "$new_file"
    echo "Renamed $file to $new_file"
  fi
done