Unix Exercise
- Create a directory with your name under the default home directory for the user “traineee”.
- Create a file “samplefile” in your home directory.
- Give the file above appropriate permissions if necessary. What do you think appropriate permissions should be?
- Turn the sticky bit on for the directory you have created
- Write a script which prompts for your name and then prints on stdout Hello “yourname” Today is “today;s date and time”
- Write a script to print the names of all the files in the current directory using for loop
- Create a file “-myfile” in your directory.
- Remove the above file
- Write 100 lines in a file each containing text “Unix is a wonderful world”. Hint : Use a loop construct
- 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