Unix DB


Soft link Vs Hard link 


1. Hard Links

Each hard linked file is assigned the same Inode value as the original, therefore they reference the same physical file location. Hard links more flexible and remain linked even if the original or linked files are moved throughout the file system, although hard links are unable to cross different file systems.
ls -l command shows all the links with the link column shows number of links.
Links have actual file contents
Removing any link, just reduces the link count, but doesn’t affect other links.
We cannot create a hard link for a directory to avoid recursive loops.
If original file is removed then the link will still show the content of the file.
Command to create a hard link is:
$ ln  [original filename] [link name] 



2. Soft Links

A soft link is similar to the file shortcut feature which is used in Windows Operating systems. Each soft linked file contains a separate Inode value that points to the original file. As similar to hard links, any changes to the data in either file is reflected in the other. Soft links can be linked across different file systems, although if the original file is deleted or moved, the soft linked file will not work correctly (called hanging link).
ls -l command shows all links with first column value l? and the link points to original file.
Soft Link contains the path for original file and not the contents.
Removing soft link doesn’t affect anything but removing original file, the link becomes “dangling” link which points to nonexistent file.
A soft link can link to a directory.
Link across filesystems: If you want to link files across the filesystems, you can only use symlinks/soft links.
Command to create a Soft link is:
$ ln  -s [original filename] [link name] 


Unix Shell comparison :




Cut & AWK : 

Cut : It can be used to cut parts of a line by byte position, character and field. Basically the cut command slices a line and extracts the text.


WHAT CAN WE DO WITH AWK ?
1. AWK Operations:
(a) Scans a file line by line
(b) Splits each input line into fields
(c) Compares input line/fields to pattern
(d) Performs action(s) on matched lines
2. Useful For:
(a) Transform data files
(b) Produce formatted reports

3. Programming Constructs:
(a) Format output lines
(b) Arithmetic and string operations
(c) Conditionals and loops

Korn shell Vs Bash shell : 



Korn Shell

Bash Shell

The script extension of the KSH shell is .kshThe script extension of the Bash shell is .sh
The path of the Korn shell in the directory structure is /bin/ksh.The path of the Bash shell in the directory structure is /bin/sh.
Approximately the Binary size of the Korn Interpreter is somewhere 1.6 MB.Bash interpreter has a binary size of 1.1 MB.
Korn shell uses the print command to print the message in the terminal.Bash shell uses the echo command to print the message in the terminal.
Korn shell has better support to loop handling as compared to the Bash shell.Bash shell can also handle loops better but not to the mark as compared to Korn shell
The Korn shell is developed by David Korn and it’s older than the Bash shell.Bash shell is developed by Freeware Software Foundation and it is a newly created shell as compared to the Korn shell.
There is less number of users using the Korn shell and the community is also less as compared to the Bash shell.Bash shell consists of a large number of active users and has a large community.
Defining variable With or without 'export' :  


  • Shell variables (defined without export) are like local variables that we can access only within that shell.
  • Environment variables (defined with export) are like global variables that we can access within the defining shell and all its child shells, processes, and commands.
  • An environment variable is a globally available, in a program and it child programs. A shell variable is only available in the current shell. To make a shell variable available as an environment variable, use export VARNAME (without dollar $).
  • Result can be seen by executing set (environment variables) & env (shell variables)  command.
Commands : 

  • $() – the command substitution
  • ${} – the parameter substitution/variable expansion
  • NF is a predefined variable whose value is the number of fields in the current record. awk automatically updates the value of NF each time it reads a record. No matter how many fields there are, the last field in a record can be represented by $NF.
    • i.e. awk '{print $NF}'


SUID and SGID File Permission

Often when a command is executed, it will have to be executed with special privileges in order to accomplish its task.

As an example, when you change your password with the passwd command, your new password is stored in the file /etc/shadow.

As a regular user, you do not have read or write access to this file for security reasons, but when you change your password, you need to have the write permission to this file. This means that the passwd program has to give you additional permissions so that you can write to the file /etc/shadow.

Additional permissions are given to programs via a mechanism known as the Set User ID (SUID) and Set Group ID (SGID) bits.

When you execute a program that has the SUID bit enabled, you inherit the permissions of that program's owner. Programs that do not have the SUID bit set are run with the permissions of the user who started the program.

This is the case with SGID as well. Normally, programs execute with your group permissions, but instead your group will be changed just for this program to the group owner of the program.

The SUID and SGID bits will appear as the letter "s" if the permission is available. The SUID "s" bit will be located in the permission bits where the owners’ execute permission normally resides.







Comments

Popular posts from this blog