UNIX Related Que/Ans
1. How can
you determine the space left in a file system?
Level:
Low
Expected
answer: There are several commands to do this: du, df, or bdf
2. How can
you determine the number of SQLNET users logged in to the UNIX system?
Level:
Intermediate
Expected
answer: SQLNET users will show up with a process unique name that begins with
oracle<SID>, if you do a ps -ef|grep oracle<SID>|wc -l you can get
a count of the number of users.
3. What
command is used to type files to the screen?
Level:
Low
Expected
answer: cat, more, pg
4. What
command is used to remove a file?
Level:
Low
Expected
answer: rm
5. Can you
remove an open file under UNIX?
Level:
Low
Expected
answer: yes
6. How do
you create a decision tree in a shell script?
Level:
intermediate
Expected
answer: depending on shell, usually a case-esac or an if-endif or fi structure
7. What is
the purpose of the grep command?
Level:
Low
Expected
answer: grep is a string search command that parses the specified string from
the specified file or files
8. The
system has a program that always includes the word nocomp in its name, how can
you determine the number of processes that are using this program?
Level:
intermediate
Expected
answer: ps -ef|grep *nocomp*|wc -l
9. What is
an inode?
Level:
Intermediate
Expected
answer: an inode is a file status indicator. It is stored in both disk and
memory and tracts file status. There is one inode for each file on the system.
10. The
system administrator tells you that the system hasn’t been rebooted in 6
months, should he be proud of this?
Level:
High
Expected
answer: Maybe. Some UNIX systems don’t clean up well after themselves. Inode
problems and dead user processes can accumulate causing possible performance
and corruption problems. Most UNIX systems should have a scheduled periodic
reboot so file systems can be checked and cleaned and dead or zombie processes
cleared out.
11. What
is redirection and how is it used?
Level:
Intermediate
Expected
answer: redirection is the process by which input or output to or from a
process is redirected to another process. This can be done using the pipe
symbol “|”, the greater than symbol “>“ or the “tee” command. This is one of
the strengths of UNIX allowing the output from one command to be redirected
directly into the input of another command.
12. How
can you find dead processes?
Level:
Intermediate
Expected
answer: ps -ef|grep zombie -- or -- who -d
depending on the system.
13. How
can you find all the processes on your system?
Level:
Low
Expected
answer: Use the ps command
14. How
can you find your id on a system?
Level:
Low
Expected
answer: Use the “who am i” command.
15. What
is the finger command?
Level:
Low
Expected
answer: The finger command uses data in the passwd file to give information on
system users.
16. What
is the easiest method to create a file on UNIX?
Level:
Low
Expected
answer: Use the touch command
17. What
does >> do?
Level:
Intermediate
Expected
answer: The “>>“ redirection symbol appends the output from the command
specified into the file specified. The file must already have been created.
18. If you
aren’t sure what command does a particular UNIX function what is the best way
to determine the command?
Expected
answer: The UNIX man -k <value> command will search the man pages for the
value specified. Review the results from the command to find the command of
interest.
UNIX
Que/Ans With Example
1.check
6th Columns without Null value from any file
=>
nawk -F"|" '($6!="")' FileName > test_24_ok
2.check
6th Columns with Null value from any file
=> nawk -F"|"
'($6=="")' FileName > test_24
3.Finding
distinct row's from any file
=> awk -F"|" '{print
$32 }' File_Name.txt | sort -u
4.For
creatin direcory from another location
=> mkdir -p
/u05/PRODDSS/data3/srcfiles/mcd
Send
mail through Unix
ð (cat
PST_Analysis ; cat INSDPWiseCnt_Diff| uuencode INSDPWiseCnt_Diff )| mailx -r Devendra@relianceada.com
-s "PST Analysis" Devendra@relianceada.com
ð /usr/bin/mailx
-s "Mount Point status" -r EmergencyMail
devendrakumar.yadav@relianceada.com < /U03/voice/scripts/diskutilization.txt
5.For
going 37072948 no rows in a file then
==> awk NR==37072948
S_VLD_COMPLETE_DATA_2008-10-23.dat
6.For File
spliting in Unix
ð split
-37072945 S_VLD_COMPLETE_DATA_2008-10-23.dat
(automatically file splitted into total rows/given row no)
7.For
deleting Particular record from a large file===> where first column No is
9999705895
=> cat merge_R_VOI_27_2008-10-27.dat|grep -v
9999705895 > test.txt
8.
Sagrigate Substrings => awk -f"|" '{print
substr($1,1,4)"-"substr($1,5,2)}' test.txt |more
9.Display
1,2,3,18,19 columns from that file
=> awk -F"," '{print $1,$2,$3,$18,$19
}' File_name | head -20
10.Cut a
string from a file and display without spacing
=> awk 'BEGIN
{OFS="|"}{print
$1,$2,$3,substr($12,1,4)"-"substr($12,5,2)}' file_name
=>awk -F"n" '{ print
substr($1,1,4) }' file_name
11 .
Display particular column($1 for 1st column) from given file
=>awk -F"," '{print
$1}' FileName
12 .Command
For search a file in unix
=> find /u04/ -name File_name
-print
13.To
print Number of Columns
=> awk
'BEGIN{FS="|"}{print NF}' File_Name | head -3
14.Print
columns which is less or greater than 500
=> nawk 'BEGIN{FS=OFS="|"}{if(NF
> 500 || NF < 500){print $0}}' File_Name > test
Devendra1.dat
File is having onlyNF=7 Record's
=>
nawk 'BEGIN{FS=OFS="|"}{if(NF==7){print $0}}' Devendra.dat > Devendra1.dat
Testing
a file with first colum having "200903" ==>
=>awk -F"|"
'{if($1=="200903")}{print $0}' S_04-01.dat > S_04-01_TEST.dat
15.For
serch and replace in
VI --> %s/old/new/g ==>%s/20081215/20081115/g
16.In Fix
Width File Search or cut
=> awk -F"n" '{ print
substr($1,124,8)}' File name
(==> $1 means whole string, 124th
position upto + 8th position display)
17.For
Updating Crontab using VI Editor
-->in Command line type
EDITOR=vi then Enter then -> export EDITOR
--> Then Type Crontab –e
18.For
concatinate two files same columns in another file
=> paste file1 file2 > file3
19.For
changing all albhabets in Capital letter from any file
=>
tr -s '[a-z]' '[A-Z]' < File_Name
20. ping
to server in unix
=> /usr/sbin/ping 97.253.32.155
21.Take
count from any file having '2009-02' records
=> awk -F"," '{print $5}'
R_SMS_CDR_2009-04-02.dat| grep '2009-02' | wc -l
22.compare
any substring from a file
=> nawk
'BEGIN{FS=","}{if(substr($3,1,7)=="2009-03"){print $0}}'
test.txt
23.for
copying whole directories
=> tar -cvf ScriptBKP.tar /u06/srcfiles/scriptbackup/*
=> tar -xvf ScriptBKP.tar
24.Insert
'2' in all record's of end of every row in file DEV_TEST.TXT
=>sed 's/$/|2/' DEV_TEST.TXT >
DEV.TXT
25. For
Executing Command Continuosly or looping
=> while true ; do smat -d | wc
-l ; sleep 2 ; echo "==================="; done ;
=>while true ; do ls -lrt | wc -l
; sleep 2 ; echo "====================="; done ;
26.
Display time also in unix prompt
=> PS1="\u-\t$"
27.Print
Particular (2nd) line from any file
=>sed -n '2,2p;2q' R_2009-07-17_03_03.dat
=>sed -n '5,5p;5q'
R_2009-08-28_00_00.dat | awk -F"," '{print $51}'
28.Convert
'2009-03-31' in 20090331
=> MDT=`echo $RDT|cut
-c1-4,6-7,9-10` ; export MDT
29.
Current Month Calculation ==>
MON1=`echo $RecordDate|cut -c6-7`
Year=`echo $RecordDate|cut -c1-4`
cal $MON1 $Year|awk NR==1|cut -c4-6
> CurrMonth
MON=`tr '[a-z]' '[A-Z]' <
CurrMonth`
30.
Connect any server through script and ftp the files
=>echo "Connecting
97.253.48.8"
ftp -n 97.253.48.8 <<!
quote user devendra1
quote pass devendraPwd
binary
cd /app_inrich/OUTPUT_INTERFACE/call_hist/dump/
lcd /u04/PisPath/pisfiles
prompt
mget DSS_INRich_subscriber_info$RD.txt
quit
31. Output
Of Date Command in unix
=> operator-17:28:11$
date
=> Thu Nov 19 17:35:46 IST 2009
32. Output Of Cal Command in unix
=>operator-17:35:47$ cal
November 2009
S M
Tu W Th
F S
1
2 3 4
5 6 7
8 9 10
11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
33.
operator-17:42:12$ls -ltr *NOV*2009-11-17*dat
-rw-rw-r-- 1 operator adhoc 554 Nov 17 18:00 R_VOI_2009-11-17_14_14.dat
operator-17:42:19$ls -ltr *NOV*2009-11-17*dat |awk '{print
$1,"|",$2,"|",$3,"VMA"}'
=>-rw-rw-r-- | 1 | operator VMA
=>
ls -ltr *JAN*2009-02-27*dat|awk '{print
$1,"|",$2,"|",$3,"VMA"}'
No comments:
Post a Comment