Skip to content

Instantly share code, notes, and snippets.

@phunehehe phunehehe/commands.md
Last active Dec 14, 2015

Embed
What would you like to do?

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
You can’t perform that action at this time.