Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6 Added perms script #114

Closed
wants to merge 1 commit into from

Conversation

Priyanshu-2005
Copy link

@Priyanshu-2005 Priyanshu-2005 commented Mar 17, 2024

Fixes #6
Added the perms script

This script takes a certain set of filenames as input and displays their permission in octal format if they exist.

OUTPUT
Commands used
ls -a
bash perms <filename1> <filename2> <filename3>......
image

Command used
bash perms
image

Explanation of the code

for file in "$@"; do
Checks for all the files given in arguments

if [ -e "$file" ]; then
Checks for existence of the file in the present working directory

permissions=$(stat -c "%a" "$file")
Retrieves the permissions of a file and assigns them to the variable permissions.

echo "Permissions of '$file' in octal format: $permissions"
Displays the permissions of the file in octal format

echo "File '$file' does not exist."
If the file is not present in the present working directory then displays that Fille does not exist

list_permissions "$@"
Calls the list_permission function

Explanation of the Output
If the script displays the permissions as 775 that means

  • The first digit (7) represents the permissions for the owner. In octal, 7 means read (4) + write (2) + execute (1), which means the owner has read, write, and execute permissions.

  • The second digit (7) represents the permissions for the group. Again, 7 means read (4) + write (2) + execute (1), which means the group has read, write, and execute permissions.

  • The third digit (5) represents the permissions for others. 5 means read (4) + execute (1), which means others have read and execute permissions but not write permissions.

@ecxtacy
Copy link

ecxtacy commented Mar 17, 2024

Good work @Priyanshu-2005.

@ecxtacy ecxtacy closed this Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write perms script.
2 participants