This section focuses on shell scripts related to file and directory permissions in Unix-like systems.
This script switches the current user to "betty" using the su
command.
#!/bin/bash
su betty
- This script prints the current username using the
whoami
command.
#!/bin/bash
whoami
- This script displays the groups to which the current user belongs using the
groups
command.
#!/bin/bash
groups
- This script changes the owner of the file "hello" to "betty" using the
sudo chown
command.
#!/bin/bash
sudo chown betty hello
- This script creates an empty file named "hello" using the
touch
command.
###
#!/bin/bash
touch hello
- This script adds execute permission for the owner of the file "hello" using the
sudo chmod
command.
#!/bin/bash
sudo chmod u+x hello
- This script sets specific permissions (754) for the file "hello" using the
sudo chmod
command.
#!/bin/bash
sudo chmod 754 hello
- This script grants execute permission to everyone for the file "hello" using the
sudo chmod
command.
#!/bin/bash
sudo chmod ugo+x hello
- This script sets specific permissions (007) for the file "hello" using the
sudo chmod
command.
#!/bin/bash
sudo chmod 007 hello
- This script sets specific permissions (753) for the file "hello" using the
sudo chmod
command.
#!/bin/bash
sudo chmod 753 hello
- This script copies permissions from the file "olleh" to "hello" using the
sudo chmod --reference
command.
#!/bin/bash
sudo chmod --reference=olleh hello
- This script adds execute permissions to all files and directories in the current directory using the
sudo chmod
command.
#!/bin/bash
sudo chmod +X *
- This script creates a directory named "my_dir" with specific permissions (751) using the
mkdir --mode
command.
#!/bin/bash
mkdir --mode=751 my_dir
- This script changes the group of the file "hello" to "school" using the
sudo chgrp
command.
#!/bin/bash
sudo chgrp school hello
- This script changes the owner to "vincent" and the group to "staff" for all files in the current directory using the
sudo chown
command.
#!/bin/bash
sudo chown vincent:staff *
- This script changes the owner and group of the symbolic link "_hello" to "vincent:staff" using the chown
-h
command.
#!/bin/bash
chown -h vincent:staff _hello
- This script changes the owner of the file "hello" from "guillaume" to "betty" using the sudo chown
--from
command.
#!/bin/bash
suo chown --from=guillaume betty hello
- This script plays an ASCII Star Wars episode in the terminal using the
telnet
command.
#!/bin/bash
telnet towel.blinkenlights.nl