Unix interview questions and answers part 6

1. Write a command to remove the prefix of the string ending with '/'.


The basename utility deletes any prefix ending in /. The usage is mentioned below:
basename /usr/local/bin/file 

This will display only file

2. How to display zero byte size files?

ls -l | grep '^-' | awk '/^-/ {if ($5 !=0 ) print $9 }'

3. How to replace the second occurrence of the word "bat" with "ball" in a file?

sed 's/bat/ball/2' < filename

4. How to remove all the occurrences of the word "jhon" except the first one in a line with in the entire file?

sed 's/jhon//2g' < filename

5. How to replace the word "lite" with "light" from 100th line to last line in a file?

sed '100,$ s/lite/light/' < filename

6. How to list the files that are accessed 5 days ago in the current directory?
find -atime 5 -type f

7. How to list the files that were modified 5 days ago in the current directory?

find -mtime 5 -type f

8. How to list the files whose status is changed 5 days ago in the current directory?

find -ctime 5 -type f

9. How to replace the character '/' with ',' in a file?

Sed 's/\//,/' < filename

sed 's|/|,|' < filename

2 Comments

If you have any doubts, Please let me know
Thanks!

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post