File permissions - anon222 - 05-09-2015
A script for the thunar custom action that displays the file permissions and can change them.
Technicaly, it will work with directories but will not change them recursively. The files and directories inside will remain unchanged.
Also it works only for a single file.
This is not something I would recommend to someone who doen't understand file permissions.
Be carefull about symbolic links! Never use this on them! chmod changes the permissions of the pointed-to file.
Thunar custom action
Name:
Description:
Code: Displays and changes file permissions
Command:
Code: /path/to/the/script %n
Appearance conditions:
Pattern:
Everything
The script:
Code: #!/bin/bash
file="$@"
PERM="$(stat --printf=%a%A "$file")"
USER_="${PERM:0:1}"
if [[ $USER_ = 7 ]]; then TF1="TRUE"; TF2="TRUE"; TF3="TRUE"
fi
if [[ $USER_ = 6 ]]; then TF1="TRUE"; TF2="TRUE"; TF3="FALSE"
fi
if [[ $USER_ = 5 ]]; then TF1="TRUE"; TF2="FALSE"; TF3="TRUE"
fi
if [[ $USER_ = 4 ]]; then TF1="TRUE"; TF2="FALSE"; TF3="FALSE"
fi
if [[ $USER_ = 3 ]]; then TF1="FALSE"; TF2="TRUE"; TF3="TRUE"
fi
if [[ $USER_ = 2 ]]; then TF1="FALSE"; TF2="TRUE"; TF3="FALSE"
fi
if [[ $USER_ = 1 ]]; then TF1="FALSE"; TF2="FALSE"; TF3="TRUE"
fi
if [[ $USER_ = 0 ]]; then TF1="FALSE"; TF2="FALSE"; TF3="FALSE"
fi
GRP_="${PERM:1:1}"
if [[ $GRP_ = 7 ]]; then TF4="TRUE"; TF5="TRUE"; TF6="TRUE"
fi
if [[ $GRP_ = 6 ]]; then TF4="TRUE"; TF5="TRUE"; TF6="FALSE"
fi
if [[ $GRP_ = 5 ]]; then TF4="TRUE"; TF5="FALSE"; TF6="TRUE"
fi
if [[ $GRP_ = 4 ]]; then TF4="TRUE"; TF5="FALSE"; TF6="FALSE"
fi
if [[ $GRP_ = 3 ]]; then TF4="FALSE"; TF5="TRUE"; TF6="TRUE"
fi
if [[ $GRP_ = 2 ]]; then TF4="FALSE"; TF5="TRUE"; TF6="FALSE"
fi
if [[ $GRP_ = 1 ]]; then TF4="FALSE"; TF5="FALSE"; TF6="TRUE"
fi
if [[ $GRP_ = 0 ]]; then TF4="FALSE"; TF5="FALSE"; TF6="FALSE"
fi
ALL_="${PERM:2:1}"
if [[ $ALL_ = 7 ]]; then TF7="TRUE"; TF8="TRUE"; TF9="TRUE"
fi
if [[ $ALL_ = 6 ]]; then TF7="TRUE"; TF8="TRUE"; TF9="FALSE"
fi
if [[ $ALL_ = 5 ]]; then TF7="TRUE"; TF8="FALSE"; TF9="TRUE"
fi
if [[ $ALL_ = 4 ]]; then TF7="TRUE"; TF8="FALSE"; TF9="FALSE"
fi
if [[ $ALL_ = 3 ]]; then TF7="FALSE"; TF8="TRUE"; TF9="TRUE"
fi
if [[ $ALL_ = 2 ]]; then TF7="FALSE"; TF8="TRUE"; TF9="FALSE"
fi
if [[ $ALL_ = 1 ]]; then TF7="FALSE"; TF8="FALSE"; TF9="TRUE"
fi
if [[ $ALL_ = 0 ]]; then TF7="FALSE"; TF8="FALSE"; TF9="FALSE"
fi
STAT_="${PERM:3:13}"
ans=$(zenity --height=450 --width=350 --list --text "File:\n<b>$file</b>\nPermissions:\n<b>${STAT_}</b>\nchange files permissions" --checklist --column "pick" --column "options" \
"$TF1" "user-read" "$TF2" "user-write" "$TF3" "user-exec" "$TF4" "group-read" "$TF5" "group-write" "$TF6" "group-exec" "$TF7" "all-read" "$TF8" "all-write" "$TF9" "all-exec" --separator=":")
if [ "$ans" != "" ]; then
searchuserread="user-read"
searchuserwrite="user-write"
searchuserexec="user-exec"
user1="0"
user2="0"
user3="0"
searchgroupread="group-read"
searchgroupwrite="group-write"
searchgroupexec="group-exec"
group1="0"
group2="0"
group3="0"
searchallread="all-read"
searchallwrite="all-write"
searchallexec="all-exec"
all1="0"
all2="0"
all3="0"
case $ans in *"$searchuserread"*)
user1="4" ;;
esac
case $ans in *"$searchuserwrite"*)
user2="2" ;;
esac
case $ans in *"$searchuserexec"*)
user3="1" ;;
esac
case $ans in *"$searchgroupread"*)
group1="4" ;;
esac
case $ans in *"$searchgroupwrite"*)
group2="2" ;;
esac
case $ans in *"$searchgroupexec"*)
group3="1" ;;
esac
case $ans in *"$searchallread"*)
all1="4" ;;
esac
case $ans in *"$searchallwrite"*)
all2="2" ;;
esac
case $ans in *"$searchallexec"*)
all3="1" ;;
esac
u=$(($user1 + $user2 + $user3))
g=$(($group1 + $group2 + $group3))
a=$(($all1 + $all2 + $all3))
result="$u$g$a"
chmod $result "$file" || { zenity --error --text="An error occurred!\ncheck if you are allowed\nto change permissions\nof the selected files"; }
fi
Bonus:
If you want to display the full path in the file name use
Code: /path/to/the/script %f
for the Thunar custom action.
Cheers
Re: File permissions - Valtam - 05-11-2015
Thank you for the share misko
Re: File permissions - anon222 - 05-13-2015
(05-11-2015, 01:32 AM)Jerry link Wrote: Thank you for the share misko
It's good for learning about file permissions. Maybe a more user friendly approach would be to use the common ones like 777 755 700 644 ...
Coulumn | Column | Column
[table][tr][td]777
[/td] [td] (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
[/td] [/tr] [tr] [td] 755
[/td] [td] (rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
[/td] [/tr] [tr] [td] 700
[/td] [td] (rwx------) The file's owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
[/td] [/tr] [tr] [td] 666
[/td] [td] (rw-rw-rw-) All users may read and write the file.
[/td] [/tr] [tr] [td] 644
[/td] [td] (rw-r--r--) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
[/td] [/tr] [tr] [td] 600
[/td] [td] (rw-------) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.[/td][/tr][/table]
|