Day 3 DevOps challenge

Day 3 DevOps challenge

Basic Linux commands(Part - 2)

✔️Linux File Permissions:

Every file and directory in your UNIX/Linux system has following 3 permissions

  • Read: This permission give you the authority to open and read a file. Read permission on a directory gives you the ability to lists its content.

  • Write: The write permission gives you the authority to modify the contents of a file. The write permission on a directory gives you the authority to add, remove and rename files stored in the directory. Consider a scenario where you have to write permission on file but do not have write permission on the directory where the file is stored. You will be able to modify the file contents. But you will not be able to rename, move or remove the file from the directory.

  • Execute: In Windows, an executable program usually has an extension “.exe” and which you can easily run. In Unix/Linux, you cannot run a program unless the execute permission is set. If the execute permission is not set, you might still be able to see/modify the program code(provided read & write permissions are set), but not run it.

File Permissions in Linux/Unix

✔️Changing file/directory permissions in Linux Using ‘chmod’ command :

syntax: chmod permissions filename

There are 2 ways to use the command –

  1. Absolute mode

  2. Symbolic mode

✔️Absolute mode:

in this mode, file permissions are not represented as characters but a three-digit octal number.

The table below gives numbers for all for permissions types.

NumberPermission TypeSymbol
0No Permission
1Execute–x
2Write-w-
3Execute + Write-wx
4Readr–
5Read + Executer-x
6Read +Writerw-
7Read + Write +Execute (all permission)rwx

Let's see an example of absoute mode :

if it a file has 764 permission then ,

  • Owner can read, write and execute.

  • Usergroup can read and write.

  • all others can only read.

File Permissions in Linux/Unix

This is shown as -rwxrw-r–

✔️Symbolic Mode in Linux:

In the Absolute mode, you change permissions for all 3 owners. In the symbolic mode, you can modify permissions of a specific owner. It makes use of mathematical symbols to modify the Unix file permissions.

OperatorDescription
+Adds a permission to a file or directory.
Removes the permission.
\=Sets the permission and overrides the permissions set earlier.

The various owners are represented as –

u

user/owner

g

group

o

other

a

all

✔️Some other basic commands:

Command

Example

Description

history

history

displays all commands used previously in the terminal.

cat >>

cat >> yourfile.ext

used to append or add content to an already existing file.

head -n

head -3 yourfile.ext

displays starting 'n' lines from the file

tail -n

tail -3 yourfile.ext

displays bottom 'n' lines from the file

diff

diff yourfile.txt otherfile.txt

shows the differences in 2 files

Thank you so much for reading

Follow me at LinkedIn to see interesting posts like this : )

https://www.linkedin.com/in/prabir-kumar-mahatha-6a0025248/