Wednesday, September 16, 2020

Can we create file in another directory ? UNIX - Privilege



Can we create file in another directory in UNIX ?

Let we understand by the help of example. 
Suppose we have two user Raj and Anil. Privilege of Raj is 700 and Privilage of Anil is 777.

here , 700 means  ( _ r w_ _ _ _ _ _ _  ) only read write permission. and
        777 means ( _ r w x r w x r w x ) all permission.

As we know that :
_        : No permission
r        : Only read permission
w       : Only write permission
x        : Only execution is permitted.

So Raj have only read/write for owner and no other permission for group member and others. Anil have all permission for  owner,group and others.

Now we understand by:


Now from the above diagram it is clear that Raj user can create any new file in Anil directory by copy command but Anil user can not create any new file in Raj directory because Raj privilege is 700 and Anil privilege is 777. I already describe above about meaning of 700 and 777.

When Anil want to create any new file in Raj directory the output is permission denied because Raj have only privilege 700 means ( _ r w_ _ _ _ _ _ _ ) only r/w for owner , group for 0 and other for 0 , Anil is neither owner nor group member for Raj he is other and other have no privilege to Raj. So he can not create new file.

Note : If any person is a member of more than one group than one group is primary and other is secondary.

UNMASK VALUE :-

This is a system default / define value. This process is done when only any new file is created.

Suppose:

    777      ( maximum permission granted )
  - 133      ( unmask value / system default value )
----------
    644       ( Default value )
----------
Now the default permission granted value is 644.
here 644 means ( _ r w _ r _ _ r _ _ )

If we want to define Unmask value from own side than run following command.
$ unmask = 177
where 177 is user define value (own choice)
For Understand Permissions see following 👇

Above diagram show every thing about User Permissions.

Tuesday, August 25, 2020

UNIX COMMAND & SECURITY SYSTEM PART - 4

 


Security system in Multi user system

First we talk about the security system of file.

Security system of file means no other user are otherwise to access the file of another user.

Let we understand command:

Command : $  ls  -l

Here :

 ls  - same as dir command in dos

-l  - for log listing of file.

Output of Command [ $  ls  -l ]

_rwxr_xr_x  3  amit  staff  411  datetime   a1

drwxr_xr_x  2  amit  staff  411  datetime   a2

---------          ----           ---------        ---------

DETAILS:

MODE OF FILE Such as:

_rwxr_xr_x

drwxr_xr_x 

NUMBER OF LINK Such as:

3

2

OWNER Such as:

amit

amit  

GROUP Such as:

staff  

staff  

SIZE OF FILE Such as:

411

411

COMMAND Such as:

datetime   

datetime   

FILE NAME Such as:

a1

a1


NOTE:

_rwxr_xr_x  3  amit  staff  411  datetime   a1

drwxr_xr_x  2  amit  staff  411  datetime   a2

Here:  _  Means ordinary files

            d  Means directory

            b  Means block read file (Such as: HDD , CDROM , Secondary Device)

            c  Means character read file (Such as: modem , printer etc). These files are also called device driver files. They are available in dev directory.

Suppose:

 


Note: Each file must have their Owner and Group. as above figure show.


SYMBOL                MEANING                                 NUMERICAL VALUE
      _                         No Permission                                           Ï†
      r                         Only read is Permitted                             4
      w                        Only write is Permitted                            2    
      x                         Only Execution is Permitted                    1                        

Form above it is clear that the numerical value of maximum number of permission is not more than ( 0 + 4 + 2 + 1 ) =7  for any owner , group and others of a file.

Detail information is given in the figure given below 👇


If we have any file than we can do following things such as :


Note: Maximum Possible Permissions are : 7 7 7

Example:

  


NOTE ABOUT GROUP:

Suppose we have three groups:

STAFF             ACCOUNTS                STORE        Group name                

amit                       amit                              raj

ajay                        anil                              raja

raja                        sumit                           ajay

  -                               -                                  -

  -                               -                                  -

Only administrator can create a group.

Only administrator can create user / login and associate to some group.



Friday, August 21, 2020

UNIX SHELL COMMAND & PIPELINING PART 3



In this article we discuss about some basic command of UNIX.These commands are very useful for operating or managing UNIX file system.

 Command 1: $ pg filename

Command is used to display constant page wise 

Example : $ pg +2  ab1

here ,  +2 for display next two pages

            -3 for display previous three pages

             q for quit


 Command 2: $ head  -n filename

 Command is used to display from header

where , n is any integer

Example : $ head -10 abc

Detail      : It will display 10 lines from header (Top)


 Command 3: $ tail  -n filename

 Command is used to display from tail (Bottom)

where , n is any integer

Example : $ tail -10  abc

Detail      : It display 10 line from bottom


 Command 4: $ file  file(s)

 Command is used to show file type.

Example : $ file  *

Detail      : Display all type of files    *|All


 Command 5: $ grep  option  string  file(s)

 Command is used for filter

Example : $ grep  amit  *

Detail      : Search amit in current directory

Example : $ grep  " Shailu"  ab*

                : $ grep  -in   amit   ab2

Detail     : where   -in  -optional [ignore] , amit - string   , ab2 - filename


CONCEPT:

If we want to run more than one command in one statement then we use pipeline concept. In pipeline output of one pipe is input of another pipe. It is represented by ( | ).

 Command 6: $ who | wc -l

Command first display all login / active users than count number of user.

Example:



 Command 7: $ who | grep   amit  |  wc  -l

 Command first display all login / active users than search 'amit' user and than count number of 'amit' user.

Example:




 Command 8: $ who | grep amit  >  aa

 Command first display all login / active users than search user name 'amit' and than save / copy it in 'aa' file.


 Command 9: $ who | grep amit | tee  aa  | wc  -l

 When we apply two operation in same field than we use tee command , like here 'amit' is save in 'aa' and also find number of 'amit ''.



 Command 10: $ file  * .c | wc  -l

Command first search those file name whose extension is ( .c ) and then show how many number of file of ( .c ) extension.


 Command 11: $ ls  -l  *c | wc  -l

 Command is used to show file.


 Command 12: If  we have any file abc and we don't know how many lines in that file and we want to display the constant of line number 26 to 75 than write the command.

$ head  -75 abc | tail -49 abc

 



 Command 13: $ PS

 Command is used to show how many process are running.

Example : command will show output such as

       PID                                   PPID                                           

 (ProcessId)                  Parent ProcessId                Terminal              Command

     3128                                 2456                                 tt02                           sh

     4132                                 4562                                 tt05                           ps

     5235                                 5632                                 tt03                          who

        -                                        -                                       -                                -                              


Note: SYSTEM CALLS
 fork ( )  :  Used to creating a process in memory
 Exet ( )  : Used to terminate any process
 Exec ( )  : Used to execute any process
 wait ( )   : wait

 Command 14: $ kill  -9  processno

This command is used  for forcefully termination.


Friday, July 31, 2020

UNIX SHELL COMMAND - PART 2



In this article we discuss about some basic command of UNIX.These commands are very useful for operating or managing UNIX file system.

Command 1: $ data

Command display date / time  (only admin can change this time / date)



Command 2:  $ cal  month  year

Note: Month will be (1 - 12)  | Year will be (1 - 9999)

Example: 
                $ cal  1998        Display calendar of 1998       
                $ cal  9 2005     Display calendar of September 2005    
                $ cal  1752        Basic Year / Starting Year
                $ cal  9 1752     Basic Year / Starting Year   


Command 3: $ cat > filename

Used to create a new file

Example:

               $ cat  > a1    File is created named a1.




Command 4: $ cat filename

Display content of file

Example:

               $ cat a1    Display content of file a1



Command 5: $ sort  -r  filename

Used for sorting ,  -r show reverse order sorting

Example:

             $ sort  -r  a1         (sort   by Z to A)  Descending order

             $ sort a1               (sort by A to Z)   Ascending order



Command 6: $ sort a1 > a1

Output of a1 redirect to a1 file



Command 7: $ cat a1

Display content of a1 file



Command 8: $ cat a1  a2

Display content of a1 file  & a2 file



Command 9: $ cat a1  >  a2

Used to copy a1 file to a2 file    i.e. (a1=a2)



Command 10: $ cat a1  a2 >  a3

Used to copy a1 and a2 into a3 file   i.e (a3 = a1 + a2)



Command 11: $ cat a1 , a2 >> a3

Used to append content of a3 file  i.e (a3 = a1 + a2 + a3)

Example:

                $ cat a2 , a1 >> a3

                $ cat a1 , a2 >> a2

                $ cat a1 >> a2



Command 12: $ man command name

Used to show online help

Example: 

                $ man who



Command 13: $ mkdir

Used for creating new directory.


Note : Unix use round robin algorithm for scheduling it is also known as time sharing.

Example : 

 If there are three process


In the above diagram first time slice is provide to a than b and than c this is also known as context switching.In this mechanism scheduler is any software who schedule the process. These scheduling process come in priority queue.

Note : Let we understand about directory in UNIX


Above represent the simple directory tree which represent root from root to current user.It is an pictorial representation. It is like  ( . /. . / jay / T3)
Here ,
             ( . ) means       / user / jay    (current directory)
             ( . . ) means     / user             (Parent directory)
Note: Parent of root directory is root. By default , we always start with current directory


Command 14: $ cd  directory name

Used for changing directory.

Example:

                $ cd T3

                $ cd . / T3

                $ cd  / user / jay / T3

                $ cd . . / . . / user / jay / T3

                $ cd . / jay / T3

                $ cd . . / user / jay / T3

                $ cd . . /. . /. . / user / jay / T3

                $ cd  . / . . / jay / T3

Note : All above commands are same regarding changing directory.



Command 15: $ cp  Source file    Target file

Used for copy any file from source directory to destination directory.

Example:

               $ cp     / user / jay / T1      / user / jay / T3 / m   [OR]    $ cp    . . / T1     . / m

         



Command 16: $ mv  Source file    Target file

Used for move or rename file source to target.

Example:

               $ mv     / user / jay / T1      / user / jay / T3 / m   [OR]    $ mv    . . / T1     . / T3 / m



Command 17: $ rmdir  Directory Name

Used for removing directory.

Example:

                $ rmdir T3


Command 17: $ rm  file(s)

Used for removing files.

Example: 

               $ rm  m        (It will remove m from jay directory by searching)

Note :

             $ rm *  ( For matching with all )

             $ rm * . *  ( For removing all files )



Command 18: $ rm  -i   ab*

ab* means file name start with ab and end with any.

-i  If we write -i than it will ask (are you sure [Y , N])


Command 19: $ rm  -r   Directory Name

-r is used for deleting directory

Example:

            $ rm -r T3    This command will delete whole tree of T3.





Command 20: $ wc  -lwc   File Name

Used for forward counting

l -   Line

w - Word

c -  Char

Example:

                $ wc -lwc ab1             Output like : 5  6  52   ( line=5, word=6, char=52)

                $ wc  -l  ab1                Output like : 5    ( line=5)

                $ wc  -wl  ab1             Output like : 6  5  ( word=6, line=5)