Welcome to Shan's Gauge UNIX Skill Level Test.
Here you will find some challenging Unix questions I put together from my daily tasks and readings. Some are the questions I answered at it-toolbox forum. You may rate yourself from 1 to 10 first, then start to look at these interesting questions and check your rating again. All answers are discussed in my blog.
The skill levels
3-5 : easy, user level, e.g. Java developer's UNIX knowledge or junior SA
6-7 : medium level, Mid to Senior Level UNIX SAs
8-9 : hard, creative, smart Senior SAs with strong computer science background or a guy who can teach UNIX courses at school of continuing eduction
10 : reserved for industry experts who can write books for the subject
Have fun!
__BEGIN__
------------------------------------------------------------------------------
0.(hard)Which directory's "." and ".." have the same i-node number (st_ino) ?
1.(medium) Why the UNIX command 'cd' must be built into a shell?
1a. What's wrong with the following shell commands? List at least two ways to fix it?
export pipe=""; ls $pipe wc -l
1c. (medium) This one is for Linux Administrators - How do you adjust the Linux kernel value for tcp_fin_timeout, tcp_keepalive_time? Can you do it with a few lines of C code?
2.(creative) Use shell utilities (Perl/sed/awk not allowed) and curl/wget to count the frequency of each word of this webpage.
For example,
curl http://webpage your_commands
the output should be:
577 n
499 a
476 data
350 span
336 class
324 br
295 b
266 div
210 post
203 li
199 http
194 href
192 com
165 if
136 the
118 style
115 color
113 title
108 quot
106 blogspot
2.5 (medium) Use shell utility to reverse text file upside down, e.g.
line1
line2
line3
...
line99
->
line99
line98
...
line1
3.(medium)Use C, Python or Perl (pick 2) to implement a pipe. e.g. "my_pipe cat file1 wc -l" = "cat file1 | wc -l"
4.(medium) Write a regular expression to match a valid IP address. ( 999.999.999.999 isn't a valid one)
5.(hard)Why only root can set sticky bit for files?
6.(web- creative) Write a curl command to login one of major sites with your id/password without using a browser. sites can be ebay, yahoo, youtube, etc.
7.(creative)How do you copy a terminal to another one? Say tty0 to tty2 and see tty0's real time typing/output from tty2 ? (very useful , you want to know!)
8.(Enterprise, medium) Write down the commands you use to extend or reduce the size of a mounted, live production vxfs filesystem (sitting on top of a mirrored volume) without using vxresize or veritas command line interface. Of course, you can't use the gui tool. (Hint, there's a difference in action sequence for extending and reducing the size)
9.(Web, medium) Describe apache AJP connector, how to you configure it? Where the connector is defined inside J2EE container, for example tomcat.
10.(Enterprise, medium) List 3 different commands you use on AIX to find out the amount of real memory? Describe the general UNIX/AIX performance tuning practice on a dedicated backend database server running AIX 5.3+, Sybase 12.5 with EMC SRDF. (Hint, only from UNIX SA's prospect, DBAs will do their parts)
11.(medium)Write a sed command to wrap each word in a text file with parenthesis. e.g. abc def -> (abc) (def)
12.(Web, medium) Describe Apache DSO vs static modules, what's the difference and advantage of DSO? How to compile/configure apache and DSO? How do you find out if your running apache instance is DSO enabled?
13.(hard) Write sed command to implement gnu grep command's -A1 and -B1 function, e.g. 'grep -A1 -B1'.
14.(medium)Write a grep command to match "the" but not "them", "theory". etc.
15.(Web, medium) What are tomcat workers? Describe what's inside workers.properties file
16.(medium) Describe the procedure and write a sample code using Perl to access mysql database, do query and update records. Do it with Python, Java?
17.(web- medium) Write a curl command to download a range of files from a site.
18.(creative)What commands you will use to spy someone's typing and record all his/her terminal session in a file?
19.(easy)At UNIX shell prompt, how do you find out which tty you are using?
20.(easy)How do you set your terminal not to display what you type?
21.(easy)What are ksh/bash "$$" and "$#" variables?
22.(easy)What's the difference between shell variables "$*" and "$@"?
23.(medium)Will this cd command "pwd; (cd/usr/local/bin); pwd" changes the current path? Why?
24.(hard) Write a sed command to add commas to numeric strings, e.g. changing "1234567" to "1,234,567"
25.(medium)Write a regular expression and use one utility (sed, perl, etc.) to look into a text file and remove all duplicated letters in any word, e.g. change abbcdee -> abcde ... zzfwxxy ->zfwxy.
26.(medium)Write a sed command to count the number of lines in several files that don't begin with a "#:"
27.(medium) Write a grep command to display 5 lines before and after the match.
28.(medium)What does UNIX command "apropos" do?
29.(medium)At UNIX prompt, how to find out all the commands related to sending signal to processes?
30.(hard)What does pid "-1" represent in "kill" command?
31.(medium)How to find out the list of available signals for kill command?
32.(medium)What does sticky bit is set for file? for directory?
33.(hard)Why only root can set sticky bit for files?
34.(hard)Can a user write into a UNIX directory?
35.(hard)From Unix internal prospect, describe a directory? How many hard links a leaf directory has?
36.(medium)Who can create a new link that points to a directory?
37.(hard)List and describe objects that a UNIX filesystem normally has.
38.(hard)In "ls -l file1" command, what information is NOT included in the inode?
39.(hard)Which directory's "." and ".." have the same i-node number (st_ino) ?
40.(medium)How do you stop a running process?
41.(medium)Which 'ls' option shows files' st_ctime, st_atime and mtime?
42.(hard)Give examples of Unix functions/commands that change each of a file's 3 time values.
43.(hard)Can you see an i-node's last access time?
44.(medium)Explain what's RPC (remote procedure call)? How it works. List one major service relies on rpc.
45.(medium)Explain the procedures to setup NIS (pick 2 from AIX,Solaris, Linux) and autofs so that users can login from any host inside NIS domain and automounte his/her home directory.
46.(hard)Describe the difference between multithreaded and multiprocess in UNIX.
47.(hard)Describe UNIX internal's "the lowest-available-file-descriptor" principle.
48.(hard)Describe 3 ways to attach STDIN to a file. Use C, Python or Perl to implement it.
49.(Web, medium) Describe the AJP connector and mod_jk module, function, configuration.
50.(Web, medium) Describe load balancing tomcat with mod_proxy, configuration and testing.
51.(Enterprise, creative) Create a solution that utilizes enterprise products Veritas VCS and Solaris 10 Zone to create virtual Solaris servers (v1, v2, v3...) that can have HA features on two physical servers, for example, two SUN M5Ks. Assume your environment has EMC SRDF, extend that design to remote replication and Disaster Recovery (DR) implementation on a remote site.
52.(Enterprise, Web, hard) Describe a 3-tier web environment, all the products you use, the detail configuration and administration operation of each product (for example, what's .war file, where do you define url mapping in tomcat? what's apache DSO?), pick 2 environments out of the 3 - Linux, Solaris and AIX.
53.(Enterprise, Web, hard) Describe the local High Availability implementation for each tier in the above 3-tier environment (the technology/products, the implementation)
54.(Enterprise, Web, hard) Describe your DR/ remote replication design (the technology and implementation) for the above 3-tier environment at both infrastructure and application levels.(Hint, there's no budget issue and you can pick any enterprise or open source products you need)
55.(Enterprise,medium) A company has over 2000 IT staffs around the world (app developers in India, SAs in Singapore, DBAs in Japan etc), as UNIX engineer, implement a solution to allow each user sign in her/his UNIX accounts and being able to have her/his home directories mounted automatically from any (Linux or Solaris) workstations around the world. Your team is also responsible backing up/restore all the users home directories.
56.(Enterprise, hard) For the above implementation, add security layers for authentication and account management.
57. (medium) List 7 types of items that a UNIX filesystem has. What are Perl's file test operators for each item?
58. (medium) What's the difference between Perl's stat and lstat function?
--------------------------------------------------------------------------------------------------------
ANSWERS: ( If answers are not here, search my blog to find out.)
Which directory's "." and ".." have the same i-node number (st_ino)?
ls -ila / will show the answer. Why? Answer.
Why the UNIX "cd" command must be built into the shells?
Because the shell forks a child process to run chdir function to change directory, once the child process terminates, the child's working directory can not affect the shell's. Therefore, the shell's working directory can never be changed by its child process. For this reason, the chdir function has to be called directly from the shell. This is why cd is built into the shells.
export pipe=""; ls $pipe wc -l
The shell take care of pipes and I/O redirection BEFORE variable substitution, therefore, it nver recognizes the pipe symbol inside pipe. The result is that the three arguments , wc and -l are passed to "ls" command as arguments.
Solutions:
a. eval export pipe=""; ls $pipe wc -l
(eval will have shell scan the command sequence twice before executing it. If the variables contain any characters that must be seen by the shell directly on the command line, then eval can be useful.)
b. Just type "ls wc -l".
sysctl -p the following configuration file:
# Decrease the time default value for tcp_fin_timeout connection.
net.ipv4.tcp_fin_timeout = 30
# Decrease the time default value for tcp_keepalive_time connection
net.ipv4.tcp_keepalive_time = 1800
# Turn off tcp_window_scaling
net.ipv4.tcp_window_scaling = 0
# Turn off the tcp_sack
net.ipv4.tcp_sack = 0
# Turn off tcp_timestamps
net.ipv4.tcp_timestamps = 0
See Hack #71 in this book.
Use shell utilities (Perl/Sed/awk not allowed) to count the frequency of each English word of this webpage.
$ curl 'http://shanit.blogspot.com/2009/10/unix-handy-tools-for-system.html' tr -sc a-zA-Z '\012' sort uniq -c sort -nr
Output:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 83662 0 83662 0 0 305k 0 --:--:-- --:--:-- --:--:-- 533k
497 n
425 span
409 data
306 a
241 b
238 class
230 br
217 div
185 style
181 post
142 font
140 color
To reverse file vertically, e.g. the last line becomes the first line.
nl input_file sort -nr sed 's/^.\{7\}//'
Will this cd command "pwd; (cd/usr/loca/bin); pwd" changes the current path? Why?
No. Commands inside () are executed in a subshell.
Write a sed command to wrap each word in a text file with parenthesis. e.g. abc def -> (abc) (def)
sed 's/[A-Za-z][A-Za-z]*/(&)/g' <inputfile> output
Use sed implement 'grep -A1 -B1' (note: grep -A -B options are NOT available on Solaris, you may sed or perl, awk instead. Sure, how do you implement it with Perl, awk? :-))
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
Write a sed command to add commas to numeric strings, e.g. changing "1234567" to "1,234,567"
sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'
Write a regular expression and use one utility (sed, perl, etc.) to look into a text file and remove all duplicated letters in any word, e.g. change abbcdee -> abcde ... zzfwxxy ->zfwxy.
2 ways to do it:
a. [shan@ipc4 ~]$ sed -n 's@\([a-zA-Z]\)\1*@\1@pg' < input > output
b. echo "aabccdee" tr -s [[:alpha:]]
Use curl to sign in a major site such as yahoo! youtube or ebay. Answer.
List 3 different commands you use on AIX to find out the amount of real memory? Describe the general UNIX/AIX performance tuning practice.
Answers.
Write a sed command to count the number of lines in several files that don't begin with a "#:"
sed 's/^#.*//' file1 file2 file3 grep -v '^$' wc -l
Write a grep command to match "the" not "thexyz..." such as "them", "theory".
What are ksh/bash "$$" and "$#" variables ?
$ is the pid of current shell
$# is the number of the positional parameters to the command
What's the difference between shell variables "$*" and "$@"?
$* expands to all positional parameters passed to the command
$@ expands to all positional parameters passed to the command, but individually quoted when "$@" is used.
What does UNIX command "apropos" do?
man -k keyword
Usage: find out all the commands related to sending signal to processes:
[root@ipc4 ~]# apropos kill grep signal
kill (2) - send signal to a process
killpg (2) - send signal to a process group
killpg (3) - send signal to all members of a process group
pkill [pgrep] (1) - look up or signal processes based on name and other attributes
pthread_kill [pthread_sigmask] (3thr) - handling of signals in threads
skill (1) - send a signal or report process status
snice [skill] (1) - send a signal or report process status
tkill (2) - send a signal to a single process
What's the default signal sent by "kill" command ?
What's this command does? "kill -9 -1"
How to find out the list of available signals for kill command?
[root@ipc4 ~]# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE
9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD
18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN
22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO
30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1
36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5
40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9
44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13
52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9
56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5
60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1
64) SIGRTMAX
or, we can see the linux programmer's manual
[root@ipc4 ~]# apropos signal grep list
signal (7) - list of available signals
[root@ipc4 ~]# man 7 signal col -b grep SIG head -20
SIGNAL(7) Linux Programmerâs Manual SIGNAL(7)
SIGHUP 1 Term Hangup detected on controlling terminal
SIGINT 2 Term Interrupt from keyboard
SIGQUIT 3 Core Quit from keyboard
SIGILL 4 Core Illegal Instruction
SIGABRT 6 Core Abort signal from abort(3)
SIGFPE 8 Core Floating point exception
SIGKILL 9 Term Kill signal
SIGSEGV 11 Core Invalid memory reference
SIGPIPE 13 Term Broken pipe: write to pipe with no readers
SIGALRM 14 Term Timer signal from alarm(2)
SIGTERM 15 Term Termination signal
SIGUSR1 30,10,16 Term User-defined signal 1
SIGUSR2 31,12,17 Term User-defined signal 2
SIGCHLD 20,17,18 Ign Child stopped or terminated
SIGCONT 19,18,25 Continue if stopped
SIGSTOP 17,19,23 Stop Stop process
SIGTSTP 18,20,24 Stop Stop typed at tty
SIGTTIN 21,21,26 Stop tty input for background process
SIGTTOU 22,22,27 Stop tty output for background process
What does sticky bit is set for file? for directory?
A sticky bit is set for an executable file, then a copy of the binary (after the first time it's executed) is saved in the swap area when the process terminated. For editors or other common programs, sticky bit is set.
Only the superuser can set the sticky bit (S_ISVTX) of a regular file. This is to prevent malicious users from setting the sticky bit and trying to fill up the swap area.
When a sticky bit is set for a directory (-t on the directories group access mode), a file in the directory can be removed or renamed only if the user has write permission for the directory and either owns the file, owns the directory or is the superuser. /tmp has sticky bit set for directory.
Can a user write into a UNIX directory? NO. Only the kernel can write to a directory.
A directory is just a file containing directory entries(filenames and associate i-node numbers). Adding, deleting, or modifying these directory entries can affect all three times associated with that directory. With permissions, we can create new files in the direcotry and remove files from it, but we can't write to the directory itself.
What is a directory? How many hard links a leaf directory has? Who can create a new link that points to a directory?
A filesystem normally has boot block, super block, i-node list, directory and data blocks.
The i-node contains all the information about the file: the file type, the file's access permission bits, the size of the file, pointers to the data blocks for the file, and so on. Most of the information in the stat structure is obtained from the i-node. Only two items are stored in the directory entry: the filename and the i-node number.
When renaming a file without changing filesystems, the actual content of the file need not be moved - all that needs to be done is to have a new directory entry point to the existing i-node and have the old directory entry removed.
Since the i-node number in the directory entry points to an i-node in the same filesystem, we cannot have a directory entry pint to an-inode in a different filesystem. This is why hardlink can't cross filesystems.
With a symbolic link, the actual contents of the file (the data blocks) contains the name of the file that the symbolic link points to.
Each i-node has a link count that contains the number of directory entries that point to the i-node. When the link count goes to 0 can the file be deleted. This is why "unlinking a file" does not always mean "deleting the blocks associated with the file." They is why the function that removes a directory is called unlink not delete.
Which directory's "." and ".." have the same i-node number (st_ino) ? /
How do you stop (not kill) a running process?
control-Z
bg - brings it to background
fg - brings it to foreground
% list jobs
Which 'ls' option shows files' st_ctime, st_atime and mtime? Give examples of Unix functions/commands that change each of a file's 3 time values.
Field | Description | Example | ls(1) option |
---|---|---|---|
st_atime | last-access time of file data | read | -u |
st_mtime | last-modification time of file data | write | default |
st_ctime | last-change time of i-node status | chmod, chown | -c |
ls -u : atime
ls -t : mtime(default)
ls -c : ctime
st_mtime is the modification time - when the contents of the file were last changed.
st_ctime is when the i-node of the file was last modified such as chmod, chown, link, etc.
Because all the information in the i-node is stored separately from the actual contents of the file,we need the changed-status time.
Can you see an i-node's last access time?
No. The system doesn't maintain the last-access time for an i-node. This is why functions like 'access' and 'stat' don't change any of the three times.
UNIX filesystem's 7 types of items and the Perl's file test operators for each item:
Figure - i-node structure
Item Perl's File Test
==== ================
file -f
directory -d
symbolic link -l
socket -S
named pipe(fifo) -p
block-special file -b
character-special file -c
What's the difference between Perl's stat and lstat function?
stat returns fs information for files and directories while lstat returns information for symbolic links.
All tomcat/apache questions are discussed at my blog's Web/Apache Section.
All AIX/Solaris related questions are discussed at my blog's Solaris and AIX Sections.
All TCP/IP related questions are discussed at my blog's TCP/IP Sections.
My thoughts about "UNIX Administrator" vs "Enterprise Administrator in UNIX environments" -
In my personal opinion, to gauge a UNIX SA's skill level, the general UNIX and computer science background are more important than the knowledge of certain enterprise products. For over 10 years, I have been working with all kinds of enterprise technologies such as Veritas VCS, VXFS, EMC, AIX, Solaris, etc. I have 12 - 15 certificates for enterprise products; but I just don't feel it is very hard to learn and administrate these enterprise products at senior levels (compare to mastering vim, sed or regular expressions); moreover, you don't need a computer science degree to create a Veritas filesystem or setup a cluster.
It is very common that a good portion of "UNIX" administrators who know how to jumpstart Solaris, attach EMC luns or setup NFS in AIX or Solaris still cut and paste/use bash shell's arrow keys to recall commands in UNIX shell; still manually update text file without knowing how to use sed/regular expression. These folks are "Enterprise System Administrators" not UNIX administrators. They happen to work in UNIX environment instead of Windows. Please keep mind that people will gauge UNIX skill levels by just watching a few things you do in UNIX such as how you use shell utilities, use vi/vim, etc. If you are weak in these areas, please fix them asap because, at least, these tools can increase your productivity.
On the other hand, people don't have experience on those enterprise products is not because they can't understand them; it is because they don't have access to the enterprise environment.
Finally, I rate what I know about UNIX as a drop of water in the UNIX knowledge sea. I'm very happy to work inside UNIX/Linux environment because I can always learn something new everyday.