Ans:/pattern if you have file open. grep if file not open.
Q.Search pattern in more files?<Polaris>
Ans:grep
Q. Search pattern in a zip file?<Polaris>
Ans:zgrep
Q.Explain egrep and fgrep?<Polaris>
Ans:egrep: Grep -e: Used for regular expressions
Q.Write a command/script which takes first 4 characters as input from output of another command?<Polaris>
Ans: echo "Anand" | cut -c 1-4
Q.How you will check server performance?<Amazon>
Ans: Top command will return all statistics
Sar:This command will return usage statistics for every 15 minute.
PRSTAT: This command used in Solaris to return server performance statistics
VMSTAT
IOSTAT
MPTAT
For memory consumption specially
free -m or free
Q.Find a pattern Anand in file Name.txt using find command?<Amazon>
Ans:find . -type f -print | xargs grep -n "Anand"
Q. Explain grep command usage?<Amazon>
Q. Search 10 digit numbers in a file:
grep '[0-9]\{10\}' anandy.txt | sed 's| |\n|g' | grep '[0-9]\{10\}'
Ans:sar | head -8 | tail -5
Q.Select top 5 processes running on host?<Amazon>
Ans:ps aux | head -6 | tail -5
Q.What you do on unix box?<Amazon>
Q.What is crontab and give a crontab entry to run a job for every minute?<Amazon>
Q.How you will move a program to run in background?<Amazon>
Ans: run.sh &
(bg also explain)
Q.Give command that run job even machine is logged off?<Amazon>
Ans:nohup
Q.How to find disk free space?<Amazon>
Ans:df -lh
Q.What is shell?<Amazon>
Ans: Interface b/w user and kernel.
Q.What is ssh?<Amazon>
Ans: It is used to connect remote machine.
Q.How you move big files from one machine to another machine?<Amazon>
Ans;sftp wldtsvcs/password@host ip
Then put command to put files on remote host or get command to get files from remote host.
Q.How you check bugs in code without tool?<Amazon>
Ans: Log into Unix machine and check logs.
Q.How do i schedule a cron job that runs every last Saturday of the month @ 2000 hours?
Ans: These are the lines needed for running the script every last saturday of the month at 8pm.
00 20 25-31 1,3,5,7,8,10,12 6 my-script.sh
00 20 24-30 4,6,9,11 6 my-script.sh
00 30 22-29 2 6 my-script.sh
Q.How to rename a set of *.txt files to *.c?
Ans:mv cant be used because it will try to find a file with name *.c. So need to use for loop kind of thing. for example:1)for i in `find / -type f -name '*.txt' -print`
do
x=`cut -d'.' -f1`
mv $i $x.c
done
2)
ls *.txt|sed -e 's/.*/mv & &/' -e 's/.txt/.c/2'|sh
Technical - UNIX
Every DBA should know something about the operating system that the database will be running on. The questions here are related to UNIX but you should equally be able to answer questions related to common Windows environments.1. How do you list the files in an UNIX directory while also showing hidden files?
ls -ltra2. How do you execute a UNIX command in the background?
Use the "&"
3. What UNIX command will control the default file permissions when files are created?
Umask
4. 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.
5. the difference between a soft link and a hard link?
A symbolic (soft) linked file and the targeted file can be located on the same or different file system while for a hard link they must be located on the same file system.
6. Give the command to display space usage on the UNIX file system.
df -lk7. Explain iostat, vmstat and netstat.
Iostat reports on terminal, disk and tape I/O activity.
Vmstat reports on virtual memory statistics for processes, disk, tape and CPU activity.
Netstat reports on the contents of network data structures.
8. How would you change all occurrences of a value using VI?
Use :
%s///g
9. Give two UNIX kernel parameters that effect an Oracle install
SHMMAX & SHMMNI
10. Command to delete large number of files in one go.
find ./* -type f -delete
11.Copy multiple files from one directory to another.
find ./* -type f -exec cp {} ./temp_dir \;
Efficient command:
find ./* -type f | xargs -i cp {} ./temp_dir/
Move large files to another directory.
ls | tail -10000 | sudo xargs mv --target ../sideline/TT-0010158611
12.Delete files older than 30 days
sudo find ./* -mtime +30 -exec rm -f {} \;
$ find . -type f -name "*.bak" -exec rm -f {} \;
13.Uptime :uptime
14.While vim,Ignore case in search pattern
set ic
Move large files:
ls | tail -10000 | sudo -u tranadm xargs mv --target ../sideline/TT-0010158611
ls | sudo -u tranadm xargs mv --target /local/transportation/NA/status-loader/redrive/new
to copy large files
sudo -u tranadm xargs cp --target /local/transportation/NA/status-loader/redrive/new
ls | sudo -u tranadm xargs mv --target /local/transportation/NA/status-loader/redrive/new
Copy files with : in file name from one host to another:
scp ./Error* anandy@gmp-parser-na-7001.iad7.amazon.com:/tmp/0009934353
rsync ./Error* anandy@gmp-parser-na-1001.vdc.amazon.com:/tmp/0013689869
Remove large files:
sudo find ./Error* -type f –delete
ls -1 | sudo xargs rm -rf
sudo find ./Error* -type f -exec rm -rf {} \;
To remove files(Including space separated files)
sudo rm -rf *.xml
To move files(Including space separated files)
sudo mv *.xml /local/transportation/NA/status-loader/redrive/new/
sudo chown tranadm 'Error_0311 2550 0003 7257 5981_2012-03-17-22:09:57622d65d9f39c4dbd9d4689e8a70f3bab.xml'
cp -r 0013689869_temp 0013689869_temp_a
if 0013689869_temp_a not exists, it will create new directory and copy all files into it. If 0013689869_temp_a exists it will copy dir 0013689869_temp into it.
To find out owner of files:
hostname% ls -lhrt | awk '{print $3}' | uniq
fangulo
hostname% ls -lhrt | cut -d' ' -f 3 | uniq
fangulo
To search only first occurrence using grep command.
grep -im 1 error Service.log.2012-03-31-11
Find out exact 10 digit numbers in a file:
egrep -o "\<[0-9]{10}\>" tt.txt
Q.What is differences b/w ps -ef and ps -auxwww?
Ans:This is indeed a good Unix Interview Command Question and I have faced this issue while ago where one culprit process was not visible by execute ps –ef command and we are wondering which process is holding the file.
Q.sort a csv file based on 2nd column<GE>
ls | tail -10000 | sudo -u tranadm xargs mv --target ../sideline/TT-0010158611
ls | sudo -u tranadm xargs mv --target /local/transportation/NA/status-loader/redrive/new
to copy large files
sudo -u tranadm xargs cp --target /local/transportation/NA/status-loader/redrive/new
ls | sudo -u tranadm xargs mv --target /local/transportation/NA/status-loader/redrive/new
Copy files with : in file name from one host to another:
scp ./Error* anandy@gmp-parser-na-7001.iad7.amazon.com:/tmp/0009934353
rsync ./Error* anandy@gmp-parser-na-1001.vdc.amazon.com:/tmp/0013689869
Remove large files:
sudo find ./Error* -type f –delete
ls -1 | sudo xargs rm -rf
sudo find ./Error* -type f -exec rm -rf {} \;
To remove files(Including space separated files)
sudo rm -rf *.xml
To move files(Including space separated files)
sudo mv *.xml /local/transportation/NA/status-loader/redrive/new/
sudo chown tranadm 'Error_0311 2550 0003 7257 5981_2012-03-17-22:09:57622d65d9f39c4dbd9d4689e8a70f3bab.xml'
cp -r 0013689869_temp 0013689869_temp_a
if 0013689869_temp_a not exists, it will create new directory and copy all files into it. If 0013689869_temp_a exists it will copy dir 0013689869_temp into it.
To find out owner of files:
hostname% ls -lhrt | awk '{print $3}' | uniq
fangulo
hostname% ls -lhrt | cut -d' ' -f 3 | uniq
fangulo
To search only first occurrence using grep command.
grep -im 1 error Service.log.2012-03-31-11
Find out exact 10 digit numbers in a file:
egrep -o "\<[0-9]{10}\>" tt.txt
Q.What is differences b/w ps -ef and ps -auxwww?
Ans:This is indeed a good Unix Interview Command Question and I have faced this issue while ago where one culprit process was not visible by execute ps –ef command and we are wondering which process is holding the file.
ps -ef will omit process with very long command line while ps -auxwww will list those process as well.
4. What is Zombie process in UNIX? How do you find Zombie process in UNIX?
When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the child's exit status. To be able to get this information, the parent calls 'wait()'; In the interval between the child terminating and the parent calling 'wait()', the child is said to be a 'zombie' (If you do 'ps', the child will have a 'Z' in its status field to indicate this.)
Zombie : The process is dead but have not been removed from the process table.
1. How do you find which processes are using a particular file?
By using lsof command in UNIX. It wills list down PID of all the process which is using a particular file.
2. How do you find which remote hosts are connecting to your host on a particular port say 10123?
By using netstat command execute netstat -a | grep "port" and it will list the entire host which is connected to this host on port 10123.
10. You have an IP address in your network how will you find hostname and vice versa?
This is a standard UNIX command interview question asked by everybody and I guess everybody knows its answer as well. By using nslookup command in UNIX
Q.sort a csv file based on 2nd column<GE>
Ans: sort -t ',' -k3 Prod1_sre_props_JDA77_90115.txt | cut -d ',' -f3
File:
ORACLE 12102@in2npdlnxdb09#cat Prod1_sre_props_JDA77_90115.txt
OWNER,TABLE_NAME,COLUMN_NAME,DATA_TYPE,DATA_TYPE_MOD,DATA_TYPE_OWNER,DATA_LENGTH,DATA_PRECISION,DATA_SCALE,NULLABLE,COLUMN_ID,DEFAULT_LENGTH,NUM_DISTINCT,LOW_VALUE,HIGH_VALUE,DENSITY,NUM_NULLS,NUM_BUCKETS,LAST_ANALYZED,SAMPLE_SIZE,CHARACTER_SET_NAME,CHAR_COL_DECL_LENGTH,GLOBAL_STATS,USER_STATS,AVG_COL_LEN,CHAR_LENGTH,CHAR_USED,V80_FMT_IMAGE,DATA_UPGRADED,HISTOGRAM,DEFAULT_ON_NULL,IDENTITY_COLUMN,EVALUATION_EDITION,UNUSABLE_BEFORE,UNUSABLE_BEGINNING
WWFMGR,HAROON,IS_FE_ENABLED,NUMBER,,,22,1,0,N,15,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,PRIMARY_ATTRIBUTE_GROUP_NAME,VARCHAR2,,,200,,,Y,14,,10,4446554D6F64656C,50726F6D6F416E616C79736973506172616D73,0.0217391304347826,996,10,12-09-2016 03:04:16 PM,23,CHAR_CS,200,YES,NO,2,50,C,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,PRIMARY_BO_NAME,VARCHAR2,,,200,,,Y,13,,10,4446554D6F64656C,50726F6D6F416E616C79736973506172616D73,0.0217391304347826,996,10,12-09-2016 03:04:16 PM,23,CHAR_CS,200,YES,NO,2,50,C,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,SHORT_NAME,VARCHAR2,,,72,,,Y,12,,325,41415050524D,574D4150454D455452494353,0.00307692307692308,694,1,12-09-2016 03:04:16 PM,325,CHAR_CS,72,YES,NO,6,18,C,NO,YES,NONE,NO,NO,,,
WWFMGR,MD_TABLE_INFO,TABLE_TYPE,VARCHAR2,,,44,,,Y,11,,2,5441424C45,56494557,0.0053763440860215,926,2,12-09-2016 03:04:16 PM,93,CHAR_CS,44,YES,NO,2,11,C,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,USE_SCHEMA_PK,NUMBER,,,22,1,0,N,10,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,IS_MONITOR_ENABLED,NUMBER,,,22,1,0,N,9,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,IS_USER_UPDATEABLE,NUMBER,,,22,1,0,N,8,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,IS_CONFIGURED,NUMBER,,,22,1,0,N,7,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,IS_TIME_ALLOCATABLE,NUMBER,,,22,1,0,N,6,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,IS_USER_DEFINED,NUMBER,,,22,1,0,N,5,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,CONFIG_CODE,NUMBER,,,22,,0,Y,4,,143,80,C80A561112391F0748,0.000538793103448276,91,143,12-09-2016 03:04:16 PM,928,,,YES,NO,7,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,SYSTEM_TABLE,NUMBER,,,22,1,0,N,3,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,TABLE_NAME,VARCHAR2,,,120,,,N,2,,1019,414354494F4E46494C544552,574F524B4F5244455250524F46494C45,0.000981,0,254,12-09-2016 03:04:16 PM,1019,CHAR_CS,120,YES,NO,16,30,C,NO,YES,HYBRID,NO,NO,,,
WWFMGR,ANAND,SCHEMA_NAME,VARCHAR2,,,120,,,N,1,,2,5343504F4D4752,5757464D4752,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,CHAR_CS,120,YES,NO,8,30,C,NO,YES,FREQUENCY,NO,NO,,,
File:
ORACLE 12102@in2npdlnxdb09#cat Prod1_sre_props_JDA77_90115.txt
OWNER,TABLE_NAME,COLUMN_NAME,DATA_TYPE,DATA_TYPE_MOD,DATA_TYPE_OWNER,DATA_LENGTH,DATA_PRECISION,DATA_SCALE,NULLABLE,COLUMN_ID,DEFAULT_LENGTH,NUM_DISTINCT,LOW_VALUE,HIGH_VALUE,DENSITY,NUM_NULLS,NUM_BUCKETS,LAST_ANALYZED,SAMPLE_SIZE,CHARACTER_SET_NAME,CHAR_COL_DECL_LENGTH,GLOBAL_STATS,USER_STATS,AVG_COL_LEN,CHAR_LENGTH,CHAR_USED,V80_FMT_IMAGE,DATA_UPGRADED,HISTOGRAM,DEFAULT_ON_NULL,IDENTITY_COLUMN,EVALUATION_EDITION,UNUSABLE_BEFORE,UNUSABLE_BEGINNING
WWFMGR,HAROON,IS_FE_ENABLED,NUMBER,,,22,1,0,N,15,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,PRIMARY_ATTRIBUTE_GROUP_NAME,VARCHAR2,,,200,,,Y,14,,10,4446554D6F64656C,50726F6D6F416E616C79736973506172616D73,0.0217391304347826,996,10,12-09-2016 03:04:16 PM,23,CHAR_CS,200,YES,NO,2,50,C,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,PRIMARY_BO_NAME,VARCHAR2,,,200,,,Y,13,,10,4446554D6F64656C,50726F6D6F416E616C79736973506172616D73,0.0217391304347826,996,10,12-09-2016 03:04:16 PM,23,CHAR_CS,200,YES,NO,2,50,C,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,SHORT_NAME,VARCHAR2,,,72,,,Y,12,,325,41415050524D,574D4150454D455452494353,0.00307692307692308,694,1,12-09-2016 03:04:16 PM,325,CHAR_CS,72,YES,NO,6,18,C,NO,YES,NONE,NO,NO,,,
WWFMGR,MD_TABLE_INFO,TABLE_TYPE,VARCHAR2,,,44,,,Y,11,,2,5441424C45,56494557,0.0053763440860215,926,2,12-09-2016 03:04:16 PM,93,CHAR_CS,44,YES,NO,2,11,C,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,USE_SCHEMA_PK,NUMBER,,,22,1,0,N,10,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,IS_MONITOR_ENABLED,NUMBER,,,22,1,0,N,9,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,IS_USER_UPDATEABLE,NUMBER,,,22,1,0,N,8,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,IS_CONFIGURED,NUMBER,,,22,1,0,N,7,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,IS_TIME_ALLOCATABLE,NUMBER,,,22,1,0,N,6,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,IS_USER_DEFINED,NUMBER,,,22,1,0,N,5,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,CONFIG_CODE,NUMBER,,,22,,0,Y,4,,143,80,C80A561112391F0748,0.000538793103448276,91,143,12-09-2016 03:04:16 PM,928,,,YES,NO,7,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,SYSTEM_TABLE,NUMBER,,,22,1,0,N,3,2,2,80,C102,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,,,YES,NO,3,0,,NO,YES,FREQUENCY,NO,NO,,,
WWFMGR,MD_TABLE_INFO,TABLE_NAME,VARCHAR2,,,120,,,N,2,,1019,414354494F4E46494C544552,574F524B4F5244455250524F46494C45,0.000981,0,254,12-09-2016 03:04:16 PM,1019,CHAR_CS,120,YES,NO,16,30,C,NO,YES,HYBRID,NO,NO,,,
WWFMGR,ANAND,SCHEMA_NAME,VARCHAR2,,,120,,,N,1,,2,5343504F4D4752,5757464D4752,0.000490677134445535,0,2,12-09-2016 03:04:16 PM,1019,CHAR_CS,120,YES,NO,8,30,C,NO,YES,FREQUENCY,NO,NO,,,
Nice post . Keep updating pega online training
ReplyDelete