Skip to content

Instantly share code, notes, and snippets.

@phunehehe
Last active December 14, 2015 19:08
Show Gist options
  • Save phunehehe/5133893 to your computer and use it in GitHub Desktop.
Save phunehehe/5133893 to your computer and use it in GitHub Desktop.

Print permissions in a way that is suitable for executing again

for i in *
do
    echo chown $(stat -c%U:%G $i) $i
    echo chmod $(stat -c%a $i) $i
done

Rename files to remove special characters

#!/bin/zsh
 
for f in "$1"/**/*
do
    if [ -f "$f" ]
    then
        dir_name=$(dirname "$f")
        file_name=$(basename "$f")
        name=${file_name%.*}
        ext=${file_name:(-4)}
        good_name=$(echo "$name" | sed -re 's/\W+/_/g' -e 's/_+/_/g')"$ext"
        [[ "$file_name" == "$good_name" ]] || echo mv "$f" "$dir_name"/"$good_name"
    fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment