Introduction to chmod
Before the actual understanding I never really tried how chmod works but I've used it nevertheless for various purposes like running a shell script , changing permissions of an aws ssh key etc.
I didn't even care about the working I just execute this good ol' command on one of my shell script chmod +x abc.sh. I came to know about chmod during one of the lectures on Operating Systems in College which was pretty usefull in a way if anyone would ask what am I doing with chmod while demonstrating something then I'd be able to answer properly
Usually the chmod command is like this
chmod XXX FILENAME
This XXX takes upto three octal digits(0-7) for example 777 ,these digits define permisions for file owner,Group and Others(public) respectively.
Suppose we have to grant Read write permission(not execute) to the user and none for the others then the corresponding command would be
chmod 600 FILENAME
# | Permission | rwx | Binary |
---|---|---|---|
7 | read, write and execute | rwx | 111 |
6 | read and write | rw- | 110 |
5 | read and execute | r-x | 101 |
4 | read only | r-- | 100 |
3 | write and execute | -wx | 011 |
2 | write only | -w- | 010 |
1 | execute only | --x | 001 |
0 | none | --- | 000 |
chmod a+rw FILENAME
a will mean for all classes (File Owner,Group and others) To remove the permission you can do
chmod a-rw FILENAME
Then there is this -R Flag it comes into action when you are changing mode of a directory and want to apply same permission to every file/directory reciding inside a directorychmod -R 700 /path/to/directory
echo "First shell script"
then just give the executable permission to our script
chmod +x test.sh
Boom your very first shell script is ready, run it with
./test.sh
You will now see the output on the command line :)Kudos on your first ever shell script!. That should be enough for introduction.
At last thank you for reading this and if you have any kind of feedback feel free to hit on this anonymous Feedback link.