Unix

Unix
Caution!!

Tuesday, 1 July 2014

Unix File Permissions

In this post we would discuss about the file permissions.

Also on the way of learning about file permissions in UNIX we would discuss the below commands :-

1.chmod

2.chown
3.chgrp

The default file permission are :-

1.666 for a file (i.e rw-rw-rw)
2.777 for a directory(i.e rwx-rwx-rwx)

*** The default permissions can be change by umask command

The long listing of a file can be read as 

-rwxrw--w-    1 anik unixsizzlers     217 Jun 26 14:08 filename  


  • The first part represnets the type of file and the file permission.The first hypen "-" of -rwxrw-w- represents the type of file .- means its a normal file.l represnets a soft link.d represensta a directpry.
  • The digits 2,3 and 4 represents the permissions of the owner of the file (i.e rwx which means read,write and executable permissions).
  • The didigts 5,6, and 7 represents the permission of the group (i.e rw- which means read ad write permission).
  • The digits 8,9,10 represents the permission of the owner (-w- which means write permission only).

1.chmod:- used to change the permission of the file  

Permission can be changed in a file by two methods

a.Relative permission.
b.Absolute permission.

a.Relative permission:-

ex:- chmod g+x,o+r filename

Which means change the permissions of the file such that group have additional executable permission and others have additonal read permission of the file.

The file after the permission change would look like


-rwxrwxrw-    1 anik unixsizzlers     217 Jun 26 14:08 filename

b.Absolute permission:-

ex:- chmod 776 filename

where 4=read permission
2=write permission
1=executable permission

Which means change the permissions of the file such that group have additional executable permission and others have additonal read permission of the file.


The file after the permission change would look like


-rwxrwxrw-    1 anik unixsizzlers     217 Jun 26 14:08 filename

2.chown:- change the ownership of the file

ex:- chown newowner filename; ls -ltr filename

The ownership of the file would change from anik to newowner.


The file after the ownership change would look like


-rwxrw--w-    1 newowner unixsizzlers     217 Jun 26 14:08 filename

2.chgrp:- change the group of the file

ex:- chgrp unixtutorial filename; ls -ltr filename

The group  of the file would change from unixsizzlers to unixtutorial.


The file after the group change would look like


-rwxrw--w-    1 anik unixtutorial 217 Jun 26 14:08 filename

Tuesday, 24 June 2014

Unix File System.

In this post we would concentrate on the following Unix File system commands.
  1. LS
  2. CAT
  3. CD
  4. MKDIR
  5. RMDIR
  6. TOUCH
  7. DF
  8. DU
  9. PWD
  10. Hard link and Soft link
1.LS:- Used to display files in unix.

  • Command to displaty the hidden files in unix?(Asked in many interview Questions)
>ls -a


  • Command to display all the files recursively in a directory?
>ls - R

  • Command to display the long listing of all the files?(Asked in many interview Questions)
>ls -lt

where l=long listing
t=sort files according to modification time.


 brw-r--r--    1 unixguy staff 64,  64 Jan 27 05:52 block         
 crw-r--r--    1 unixguy staff 64, 255 Jan 26 13:57 character     
 -rw-r--r--    1 unixguy staff     290 Jan 26 14:08 compressed.gz 
 -rw-r--r--    1 unixguy staff  331836 Jan 26 14:06 data.ppm      
 drwxrwxr-x    2 unixguy staff      48 Jan 26 11:28 directory     
 -rwxrwxr-x    1 unixguy staff      29 Jan 26 14:03 executable    
 prw-r--r--    1 unixguy staff       0 Jan 26 11:50 fifo          
 srw-rw-rw-    1 unixguy staff       0 Jan 26 12:00 socket        
 lrwxrwxrwx    1 unixguy staff       3 Jan 26 11:44 link -> dir   
 -rw-rw----    1 unixguy staff     217 Jan 26 14:08 regularfile   
 where 1st field indicates file permission
2nd field indicates number of hard links
3rd fiels indicatesowner of the file
4th field indicates the size of the file
5th field indicates the modification time 
6th and the last field indicates the file name

2.CAT:- gives the content of the file.

>cat filename

3.CD:- change directory

>cd /tmp/unix/dir1

4.MKDIR:- make directory

>mkdir dir2

5.RMDIR:- remove directory


  • Command to delete a directory and all the contents inside it?Directory has many sub directories?(Asked in many interview Questions)
>rmdir -R /tmp/unix/dir1

6.TOUCH:-used to create a zero byte file

>touch filename

7.DF( Disk free space):- Displays the amount of available freespace for filesystem.


df -k

where k=shows file size in 1024 bytes instead of 512 bytes

> df -k
 Filesystem    1024-blocks      Free %Used    Iused %Iused Mounted on
 /dev/hd4            32768     16016   52%     2271    14% /
 /dev/hd2          4587520   1889420   59%    37791     4% /usr
 /dev/hd9var         65536     12032   82%      518     4% /var
 /dev/hd3           819200    637832   23%     1829     1% /tmp
 /dev/hd1           524288    395848   25%      421     1% /home
 /proc                   -         -    -         -     -  /proc
 /dev/hd10opt        65536     26004   61%      654     4% /opt

8.DU(Disk Usage):-Gives the filespace usage

>du -sk

where k=shows file size in 1024 bytes instead of 512 bytes
s= report only the sum of the usage in the current directory, not for each file

 132456  Dir1

 178645  Dir2

9.Hard link and Soft link (Asked in many interview Questions)

Firstly what is a link in Unix?

A link in UNIX is a pointer to a file. Like pointers in C , links in UNIX are pointers pointing to a file.
 > cat file1
Unix

Creating Hard link:- ln file1 file2

Creating Soft link:- ln -s file1 file 3

After links are created

>cat file 2
Unix
>cat file 3
Unix

How to list the link files ?

$ ls -li 
total 20 
9962464 -rw-r--r-- 2 guru users 8 Mar  9 file1 
9962464 -rw-r--r-- 2 guru users 8 Mar  9 file2 
9962471 lrwxrwxrwx 1 guru users 5 Mar  9 file3 -> file1

If you see the idone number 9962464 is same for both the original file and the   hard link file.The number of links are also mentioned as two.

Where as for the soft link file -> indicates its a soft link to the original file file1.

The size of the soft link is the length of the filename of the original file.The original file is "file1" length of 5 hence the size of soft link is 5.


If the original file i.e file1 is deleted the soft link i.e file3 would not be   accessible but the hard link file2 would be accessible.



Sunday, 22 June 2014

Unix General Purpose Commands.

In this topic of discussion we would cover the following Unix General Purpose Commands.

  1. man
  2. cal
  3. echo
  4. bc
  5. rev

1.MAN:-manual help of unix.


  • How to get help for a command in unix os?
>man ps

(this will give you the manual help of how ps(process staus) command should be used in unix.it will also have the syntax of the command usage.)

2.CAL:- the calendar


This command is used to give the calender of a particluar month or year.

>cal [month] [year]

where [month] and [year] are optional.

>cal 03 2014
gives the calender of march 2014

>cal 

gives the calender of the current month

3.ECHO:-Displays a message

This command is used to display a particular message in unix.

>echo "message"
message

>echo $$
gives the currently running process.

4.BC:-Binary calculator

>bc 10+20
30

5.REV:- gives the reverse of the output.(Important asked in several interviews)

> echo "unix" | rev

xinu






Thursday, 19 June 2014

Unix Basics.

We would start with Unix Basics.Most of the interviewers would start with this set.

So we think if you start off well ,the journey would be pretty smooth.

  • Why production support servers use Unix OS,not  Windows or Andrios OS?
Multiuser,Multitasking,Secure,Unix deals with operations on files hence it is easy to operate.

  • What is kernel and Shell in Unix?
Kernel is the heart of Unix Operating system.It allocates time and memory to programs.It handles filestorage.

Shell act as an interface between user and the kernel.When user types a command shell translates it into a language the kernel understands and pass it to the kernel to execute.After logging in to UNIX OS,once username and password is checked for authentication the next program that runs is the shell.

  • What are  processes in unix?(Important asked in several interviews)
Each and every program that runs in unix is a process.One can view the processes running by using "ps" command.  ps -ef option gives us the detailed output.

ex:-
>ps -ef


USER       PID PPID %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

saml      1713  1709  0 Dec10 pts/0    00:00:00 wget 


where wget=process running
1713=processid
1709=parentprocess id

  • What is a zombie process?(Important asked in several interviews)

Zombie process is a process  in which the child dies before the parent process. 
In this case only the structural information   of the process is still in the process table.

  • What is the command to find out the type of Unix operating system you are using?
>uname

  • How to find the servername from the ipaddress given?(Important asked in several interviews)
>nslookup 10.23.45.67

  • How to find the username with which you have logged in to the server?
>whoami

  • How to kill a particular process?(Important asked in several interviews)
>kill -9 1913 (where 1913 is the pid and -9 option is to forcefully kill)

  • How to find the terminal name in unix?
>tty

  • How to find out  how long the server is running?(Important asked in several interviews)
>uptime


  • Command to find out the name of the server you are currently logged in to ?
>hostname





Introduction-We are just born.

THANK YOU!!!!

Thanks for visiting us. Its indeed a pleasure on having you here , at our blog. 

Say goodbye to the days of pondering over multiple websites to gather set of relevant unix questions for your production or application support job interview.This blog is totally dedicated on providing one stop answer to all unix related interview questions.

What can you expect from us ?

We have put together 4-5 years of collective experience of application and production support in preparing this blog.It has our first hand experiences of the type of questions one can expect while attending an unix production support job interview.So if you are one looking for a job change for the role of an Application/Production support engineer we have the below points to offer you:-
  1. Unix Basics.
  2. Important unix commands and their usage with example .
  3. Detail explanation of the important commands (asked in most interviews),
  4. Small Shell Scripts to understand the basics of shell scripting.
  5. General Application support job related interview questions.
  6. Puzzles asked in job interviews.
  7. Recent Application support job openings.
Here we go !!!!