5 min read

Linux: Beginner's Guide 2

Introduction to Linux OS - Beginner's guide 2

In this article we will explore arguments in commands, file permissions and more.

  1. Manual in CLI
  2. Using Commands with Switches
  3. Understanding File Permissions
  4. Changing File Ownership
  5. 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.

Manual from any commands

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.

Commands Definitions
-hNote: switches are defined by(hyphen) - or -- that tells the shell to get certain info from the given command. e.g -h, --help

All these commands provides guidance and use case to each command . e.g man -h, uname --help.
--help
man
whatisProvide the description of commands. e.g whatis uname, whatis ssh
aproposHelps to find command that you only know few keywords of its uses or functionality. e.g apropos remote, apropos key

Examples of some of the commands.

(man)ual page of whatis command

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.

Output of man whatis command

Example of using apropos command

Example of apropos. This lists all the commands related to secure shell (SSH)
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.

Manual page of uname and their switches 
Understanding File permissions

Security is a big concern for Linux when system is used by multiple users. The file authorisation defined by two parts.

  1. Change Ownership        define who owns the file    (Chown)  
  2. 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.

User TypePermissions
User - Owner of the file
- User also called an Owner
Group- User - group can contain multiple users.
- All users in the group have the same file permissions to the file.  
Others- Any other users who has access to a file
- Does not own the file
- Does not belong to a Usergroup
- Anyone
Linux File Permission defined using letters.
Changing file ownership

Using Chown Command

sudo chown <user> <filename>
┌──(kali㉿Kali)-[~/Demo]
└─$ sudo chown root TestFile
Chown command to change file ownership

Changing file owner and group name command

sudo chown <user>: <group> <file>
Changing user (owner) and group name of the 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.

  1. Numeric Mode  File permission represented as Octal value
  2. Symbolic Mode    File permission represented as Symbol
Octal value Permission Type Symbole
0 No Permission - - -
1 Execute - - X
2 Write - W -
3 Execute + Write - W X
4 Read r - -
5 Read + Execute r - X
6 Read + Write r W -
7 Read + Write + Execute r W X

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.

Changing file permission using Chmod command
Symbolic Mode

This mode changes permissions for a specific owner, we will be using combination of Operators and Symbols shown on the table below.

Operator Description
+ Add permission to file or directory
- Remove permission
= Override and set permission
SymbolDefinition
uUser / Owner
gGroup
oOther
aAll

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