Saturday 21 July 2012

Unix Assignment-2 - Answers


Unix Assignment-2 - Answers

  1. Create a tree structure named ‘training’ in which there are 3 subdirectories – ‘level 1’,’ level2’ and ‘cep’. Each one is again further divided into 3. The ‘level 1’ is divided into ‘sdp’, ‘re’ and ‘se’. From the subdirectory ‘se’ how can one reach the home directory in one step and also how to navigate to the subdirectory ‘sdp’ in one step? Give the commands, which do the above actions?

Ans :  To navigate from ‘se’ to home , the command is cd
To navigate to sdp from se – cd /home/training/level1/sdp


  1. How will you copy a directory structure dir1 to dir2 ? (with all the subdirectories)

Ans : cp –R dir1 dir2


  1. How can you find out if you have the permission to send a message?

Ans : ls -l


  1. Find the space occupied ( in Bytes) by the /home directory including all its subdirectories.

Ans : du -sb


  1. What is the command for printing the current time in 24-hour format?

Ans : date ‘+%R’ or date ‘+%H:%M:%S’


  1. What is the command for printing the year, month, and date with a horizontal tab between the fields?

Ans : date ‘+%Y%t%m%t%d’


  1. Create the following files: chapa, chapb, chapc, chapd, chape, chapA, chapB, chapC, chapD, chapE, chap01, chap02, chap03, chap04, chap05, chap11, chap12, chap13, chap14, and chap15.
    
     Ans: cat > chapa
type Contents of file
Ctrl+D
cat > chapb
type Contents of file
Ctrl+D
cat > chapc
type Contents of file
. . .
cat> chap14
type Contents of file
Ctrl+D
cat> chap15
Contents of file
Ctrl+D



  1. With reference to question 7, What is the command for listing all files ending in small letters?

Ans : find . –name “*[a-z]”


  1. With reference to question 7, What is the command for listing all files ending in capitals?

Ans : find . –name “*[A-Z]”


  1. With reference to question 7, What is the command for listing all files whose last but one character is 0?

Ans: find . -name “*0?”


  1. With reference to question 7, What is the command for listing all files which end in small letters but not ‘a’ and ‘c’?

Ans :  find . -name “*[^ac]” or  find . –name “*[b d-z].*” or


  1. In an organisation one wants to know how many programmers are there. The employee data is stored in a file called ‘personnel’ with one record per employee. Every record has field for designation. How can grep be used for this purpose?

Ans : grep -c programmer personnel


  1. In the organisation mentioned in question 12 how can sed be used to print only the records of all employees who are programmers.

Ans: sed -n “/programmer/p” personnel


  1. In the organisation mentioned in question 12 how can sed be used to change the designation ‘programmer’ to ‘software professional’ every where in the ‘personnel’ file

Ans :  sed -e “s/programmer/software professional/g” personnel


  1. Find out about the sleep command and start five jobs in the background, each one sleeping for 10 minutes.

Ans:  sleep 600 & sleep 600 & sleep 600 & sleep 600 & sleep 600 &


  1. How do you get the status of all the processes running on the system? i.e. using what option?

Ans : ps

No comments:

Post a Comment

TCS aspire communication quiz solutions...