0byt3m1n1
Path:
/
data
/
1
/
.snapshot
/
daily.2025-03-11_0010
/
[
Home
]
File: rename_special_dir.sh
#!/bin/bash # Check if a directory argument is provided if [ $# -eq 0 ]; then echo "Usage: $0 <directory>" exit 1 fi # Assign the directory name from the first argument DIR="$1" # Check if the provided argument is a valid directory if [ ! -d "$DIR" ]; then echo "Error: '$DIR' is not a valid directory." exit 1 fi # Change to the target directory cd "$DIR" || exit # Loop through all files in the directory #for file in *; do #for file in `find $DIR -type f ` ; do #-type d -name '.quarantine' -prune -o -type f -print #for file in `find $DIR -type d -name '.quarantine' -prune -o -type d ` ; do find $DIR -type d -name '.quarantine' -prune -o -type d|while read file do # Check if it's a regular file echo "Checking dir $file" if [ -f "$file" ]; then # Check if the filename contains any of the specified special characters #if [[ "$file" =~ [\ \$\%\#\@\!\^\&\~\`\*\+\<\>\?\"\'\ ] ]]; then if [[ "$file" =~ [\ \$\%\#\@\!\^\&\~\`\*\+\<\>\?\"\'\ ] ]]; then # Create a new filename by removing all the specified special characters #new_file=$(echo "$file" | sed 's/[$%#@!\^&~`*+<>?"\x27]\ //g') new_file=$(echo "$file" | sed 's/[\ \$\%\#\@\!\^\&\~\`\*\+\<\>\?\"'\''\ ]//g') # Rename the file if the new filename is different if [ "$file" != "$new_file" ]; then mv "$file" "$new_file" echo "Renamed '$file' to '$new_file'" fi fi fi done
© 2017 -
ZeroByte.ID
.