Simple Unix commands

Q) in a growing log file how will you see the 1st 99 lines?

Ans):-head -99 – display 1 st 99 lines tail -99 – display last 99 lines

Q) How to display top 10 users Who | head -10 | wc –w

Ans):- use below command Who | head -10

Q) write grep commands to select the lines that have exactly two characters

Ans):- grep “^..$” filename

Q) what is the difference between SED and GREP ? Which one is more better and why?

Both serves the purpose of “pattern matching” in files.SED has more features compared to simple GREP.
Ex: like replacement of existing string with new string. Deleting the lines in a file etc

Q): what is the difference between KILL and KILL -9?

Ans):- Kill allows the child processes to be killed before parent process is killed. Kill -9 forcefully kills the process without giving time to child processes to be killed. In IPC architecture, it’s not good idea to kill forcefully using “-9” option.

Q) How to display a file name which has zero bytes in size.
Ans)- we can find using find command.
find / -size 0
This will print all files under / which has 0 size.

Q) what is ls -ltd?
Ans):-ls – ltd
current directory information.
Option l: Long listing
t: Time Stamp
d: Information about current directory
(Useed with -l Option)

Q) Assume the following files are in the working directory prompt> ls -l tasks -rw-r–r– 1 alex student 1423 Feb 21 14:01 tasks What command can Alex use to give everyone permission to write to the file?
What will the ls -l command display if he does so?
# 2
chmod 666 tasks will give all users (owner, group and
others) the read-write permission.
r = 4
w = 2
x = 1
therefore rw = 4+2 =6

ls -l : lists a large amount of information of all non-
hidden files and directories in the current working
directory. eg (permissions, owners, size, and when last

Q) Cut a string based on Position and seperate them by a delimiter

Ex:- iamLearning NetezzaDB  as required output Learning,Netezza,DB,lern
Ans):- echo “vamshiKrishna” | awk ‘{print substr($0,2,2),substr($0,6,2)}’ OFS=”,”


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s