-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpermissions_script.sh
More file actions
executable file
·52 lines (40 loc) · 1.89 KB
/
permissions_script.sh
File metadata and controls
executable file
·52 lines (40 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
echo "Starting the File and Directory Permissions Script..."
# Create sample files and directories
echo "Creating sample files and directories..."
touch file1 file2
mkdir dir1 dir2
echo "Sample files and directories created: file1, file2, dir1, dir2"
# Display current permissions
echo "Displaying current permissions for files and directories:"
ls -l file1 file2 dir1 dir2
# Change permissions using chmod
echo "Changing permissions using chmod..."
chmod 744 file1 # Owner: read/write/execute, Group: read, Others: read
chmod 640 file2 # Owner: read/write, Group: read, Others: no access
chmod -R 755 dir1 # Recursive: Owner: read/write/execute, Group: read/execute, Others: read/execute
chmod 700 dir2 # Owner: full access, Group: no access, Others: no access
echo "Permissions updated."
# Display updated permissions
echo "Updated permissions for files and directories:"
ls -l file1 file2 dir1 dir2
# Change ownership using chown
echo "Changing ownership using chown..."
chown $USER file1 # Change owner to current user
chown $USER: dir1 # Change owner and group to current user
echo "Ownership updated."
# Change group using chgrp
echo "Changing group using chgrp..."
chgrp $USER file2 # Change group to current user
chgrp $USER dir2 # Change group to current user
echo "Group updated."
# Display final permissions, ownership, and group
echo "Final permissions, ownership, and group for files and directories:"
ls -l file1 file2 dir1 dir2
echo "Script execution completed successfully!"
#Meaning of chmod +x:
chmod: This command changes the permissions of a file or directory.
+x: This adds the execute (x) permission to the file or directory.
Purpose:
When a file has the x (execute) permission, it can be run as a program or script.
For example, if you have a script file like script.sh, running chmod +x script.sh allows you to execute it directly by typing ./script.sh.