Skip to content

Instantly share code, notes, and snippets.

@dev01d
Last active November 9, 2023 00:27

Revisions

  1. dev01d revised this gist Nov 9, 2023. 1 changed file with 20 additions and 13 deletions.
    33 changes: 20 additions & 13 deletions fixperms.sh
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,26 @@
    #!/usr/bin/env bash

    #
    ##
    ### Fix file pemissions
    ### dirs 755 files 644 and does not ignore dot files
    ### dirs 755 files 644
    ##
    #
    echo -e "\e[1;25;91m\nThis includes dotfiles.\e[0m\n"
    read -r -p "Are you sure? [Y/n] " response
    response=${response,,} # tolower
    if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then
    if [ "$1" == "" ] ; then
    echo -e "\e[1;25;91m\nPlease enter a valid directory path\e[0m\n" ; exit 1
    else
    find $1 -type d -exec chmod 755 {} \;
    find $1 -type f -exec chmod 644 {} \;
    echo -e "\e[1;25;32m\nProbably good now.\e[0m\n"
    fi
    fi

    CWD="$(pwd)"
    echo -e "\e[1;25;33m\nFixes file and dir perms in current working directory\e[0m\n"
    read -p "Include hidden files (Y/n)? " answer
    case ${answer:-y} in
    y|* )
    echo -e "\e[1;25;32m\nFixing Files (755)\e[0m"
    find $CWD -type d -exec chmod 755 {} \;
    echo -e "\e[1;25;32mFixing Files (644)\e[0m"
    find $CWD -type f -exec chmod 644 {} \;
    ;;
    n|N )
    echo -e "\e[1;25;32m\nFixing Files (755)\e[0m"
    find $CWD -not -path '*/.*' -type d -exec chmod 755 {} \;
    echo -e "\e[1;25;32mFixing Files (644)\e[0m"
    find $CWD -not -path '*/.*' -type f -exec chmod 644 {} \;
    ;;
    esac
  2. Jason revised this gist Aug 1, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fixperms.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    #
    ##
    ### Fix file pemissions
    ### dirs 755 files 644 and ignores dot files
    ### dirs 755 files 644 and does not ignore dot files
    ##
    #
    echo -e "\e[1;25;91m\nThis includes dotfiles.\e[0m\n"
  3. Jason revised this gist Aug 1, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fixperms.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/bin/bash
    #!/usr/bin/env bash
    #
    ##
    ### Fix file pemissions
  4. Jason created this gist Nov 30, 2017.
    19 changes: 19 additions & 0 deletions fixperms.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #!/bin/bash
    #
    ##
    ### Fix file pemissions
    ### dirs 755 files 644 and ignores dot files
    ##
    #
    echo -e "\e[1;25;91m\nThis includes dotfiles.\e[0m\n"
    read -r -p "Are you sure? [Y/n] " response
    response=${response,,} # tolower
    if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then
    if [ "$1" == "" ] ; then
    echo -e "\e[1;25;91m\nPlease enter a valid directory path\e[0m\n" ; exit 1
    else
    find $1 -type d -exec chmod 755 {} \;
    find $1 -type f -exec chmod 644 {} \;
    echo -e "\e[1;25;32m\nProbably good now.\e[0m\n"
    fi
    fi