Linux: Beginner's Guide 2
In this article we will explore arguments in commands, file permissions and more.
- Manual in CLI
- Using Commands with Switches
- Understanding File Permissions
- Changing File Ownership
- Changing File Permission
Manual in CLI
It is kind of overwhelming not knowing what to do, when you first start your command prompt. Thankfully, we have a simple commands that helps us to understand what each one of the commands does.
Screenshot below shows the manual commands, trying to help us find more info and how to use them. Just like man commands, we also have -h and --help commands to get help.
Try out these guidance commands on your Linux Distro and get a good understanding of how each commands functions, especially apropos that let you search for any commands based on its functionality.
Examples of some of the commands.
Make sure to leave a space between each commands, as shown in the screenshot above. As per our command, we are getting a manual of whatis command in screenshot below.
Example of using apropos command
Using commands with switches
Commands can take arguments, also known as switches that gives specified result. We have already looked at few samples from topic such as -help and --h.
Lets find out more info about our system. In order to do this, we need to use uname command with -a switch, that prints all information about the system. If we simply type uname, its only going to return Linux.
Understanding File permissions
Security is a big concern for Linux when system is used by multiple users. The file authorisation defined by two parts.
- Change Ownership define who owns the file (Chown)
- Change mode (Permission) define who can do what (Chmod)
Any user that creates a file, becomes an owner of that file, this can be modified by (Chown) command, and (Chmod) command defines who gets the permission to access these files.
There are 3 types of owners of the files.
Changing file ownership
Using Chown Command
sudo chown <user> <filename>
Changing file owner and group name command
sudo chown <user>: <group> <file>
Command for changing group name. Chgrp command means change group only.
sudo chgrp <group> <file>
Changing File Permission
Previously we looked at who has the ownership of the file, and how it modified to different users and group.
Now, we will check how we can change permission to the files and directory. This done by using Chmod command. There are two method you can change your file.
- Numeric Mode File permission represented as Octal value
- Symbolic Mode File permission represented as Symbol
We are going to be using Numeric Mode (Octal value) to change the file permission. Each octal value represent what Permission Type is given to the file and how it would represented on CLI using Symbols.
Numeric Mode
Command for changing file permission using octal values.
chown 777 <filename>
The above command change permission for User, Group, Others (777). In Octal value, number 7 gives permission to Read + Write + Execute.
Symbolic Mode
This mode changes permissions for a specific owner, we will be using combination of Operators and Symbols shown on the table below.
Command to change file permission using symbols
chmod o-rwx <file>
This commands removes read, write and execute permission to others.
In Linux, everything is a file!
The whole architecture of the Linux Operating system is made of files. This includes everything from system to processes, files, directories, sockets, pipes is represented by a file descriptor abstracted over the virtual filesystem layer in the kernel.
Few points about groups
- /etc/group Group contains all the groups defines in the system
- groups This command list all the group you're part of in CLI
- newgrp This command create a new group and work on it.
- chgro This commands changes to different group
- 2 Groups cannot own the same file
Member discussion