Unix Sample Questions

How to count no of blank lines in a file?

Grep –c “^$” <filename>

How to remove Empty lines form a given file?

Grep –v “^$”  filename > temfilename
Mv  tempfilename  filename

What is pattern to search 4 digit word in a file?

Grep “\<[0-9] [0-9] [0-9] [0-9]\>” filename

What is pattern to search the line having only three characters?

Grep “^…$” filename

What is pattern to display lines ending with “$” character in a given file?

Grep “\$$” filename

How to display 2 and 4 th fileds from a given file if the delimetr is “:”?

Cut –d”:” –f 2,4 filename

How to display unique lines from a given file?

Sort –u filename

How to eliminate completely duplicate lines from a given file?

Uniq –u filename

How to remove all duplicate lines from a file?

Uniq –u filename > tempfilename

Mv  tempfilename  filename

How to delete “hello” word from a given file?

Sed “s/hello//” filename

How to compare two files are same or not?

Cmp

How to display the first 10 lines from a file?

Head  -10  filename

Write a one line command to convert all the capital letters of a file "test" into lower case?

cat filename | tr "[A-Z]"  "[a-z]"

The pipeline to list the five largest files in the current directory is

 ls -l | tr -s ' ' | sort -t ' ' -fnr +4 -5 | head –5

The pipeline to find out the number of times the character ? occurs in the file is 
 tr -dc '?' < file | wc -c   ( Delete all the characters except ? and then make a word count.)

How to count total no. of users working in the system?

Who | wc –l

How to display the lines from 5 to 10 from a given file?

Head -10 filename | tail +5

What will be output of following command?

echo “Tecnosoft” | wc –c
9

What is the default umask?

022

What is the default permission for File & Directory?

The default privileges for file : 644 
The default privileges for directory :  755

What UNIX command will control the default file permissions when files are created?

Umask

Explain the read, write, and execute permissions on a UNIX directory.

Read allows you to see and list the directory contents.

Write allows you to create, edit and delete files and subdirectories in the directory.

Execute gives you the previous read/write permissions plus allows you to change into the directory and execute programs or shells from the directory.

What is chmod, chown and chgrp?

Chmod : It is used for to change permissions on files
Chown : It is used for to change ownership of a file
Chgrp : It is used for to change group of the file

Unix Tips

Have a Unix Problem
Unix Forum - Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.