Friday, October 19, 2012

Unix Exercises


                                                Unix Exercise


  1. Create a directory with your name under the default home directory for the user “traineee”.
  2. Create a file “samplefile” in your home directory.
  3. Give the file above appropriate permissions if necessary. What do you think appropriate permissions should be?
  4. Turn the sticky bit on for the directory you have created
  5. Write a script which prompts for your name and then prints on stdout Hello “yourname” Today is “today;s date and time
  6. Write a script to print the names of all the files in the current directory using for loop
  7. Create a file “-myfile” in your directory.
  8. Remove the above file
  9. Write 100 lines in a file each containing text “Unix is a wonderful world”.        Hint : Use a loop construct
  10. Write a shell script which will take 3 command line arguments and perform arithmetic The 3 args in the order are number number operation
number is a normal integer
operation could be sum, difference or product
Hint (Use functions, $#, case, expr etc)


Use tail to show the contents of dynamically growing file.
Hint echo a message in a file using infinite loop . also place a delay so that the file doesn’t grow very rapidly. Open one more session to run tail.   

Given a file named “/data/training/sam/inputfile”, do the following in separate scripts
a.       Print the count of all the blank lines
b.      Print all the lines having the string “new” in them
c.       Print all the lines having the last field greater than 20000
Hint:          Use awk

Copy all the files and subdirectories under /data/training/sam to /data/training/yourgroupdirectory/.
Hint: Use tar cvf to create the tar first from /data/training/sam and then untar the created tar under /data/training/yourgroupdirectory using tar xvf
           
Use the find command in /data/training/sam (separate scripts)
d.      To print all the files having 0 bytes
e.       To print all the directories
f.       To print all the files having only read permissions for u,g and o.

Use grep or related filter to print lines containing either Arizona or California (case insensitive search) in the file /data/training/sam/inputfile.

Read the file /data/training/sam/inputfile line by line and print each line followed by a line saying “This was line n “  n=1,2,3..

In the file ( containing 50 lines “Unix is a wonder….”, replace all the occurrences of wonderful with gruesome )
Also add “This” at the start of each and every line


Write a shell script which will write a warning to a file if any of the local filesystems exceeds a certain limit (70 %). The script would write the date and time as well as the name of the filesystem along with the current capacity in percenatge.



These are the contents of  /data/training/sam/inputfile
FNAME   LNAME STATE   AGE AMOUNT
mark         horton  california      23      40000
rafael         perez   new mexico  21      25000
melody      moses  alabama        22      10000


joe     buselmeir       new york 31     50000
tim     noble           arizona 41      12000

No comments:

Post a Comment

Hyderabad Trip - Best Places to visit

 Best Places to Visit  in Hyderabad 1.        1. Golconda Fort Maps Link :   https://www.google.com/maps/dir/Aparna+Serene+Park,+Masj...