Basic sed tricks
1.What is sed? -
sed is stream editor, a Unix tool for working with streams of text data
2.How do you substitute strings with sed?
- Use ’s/old/new’ command, so sed ’s/hello/goodbye/’ would substitute the occurrence of the word hello to goodbye.
3.How do you inject text with sed?
- & in the substitution string defines the pattern found in the search string. As an example, here’s us trying to find a word ‘hello’ and replacing it with ‘hello and how are you’: echo ‘hello there’ | sed ’s/^hello/& and how are you/’
4.Can I find several patterns and refer to them in the replacement string?
- Yes, use (pattern) and then refer to your patterns as \1, \2, \3 and so on.
5.If the string is ‘old old old’ and I run ’s/old/new’, I get ‘new old old’ as the result. I need ‘new new new‘.
- You forgot the global modifier, which would replace every occurrence of the pattern with the substitution. ’s/old/new/g‘ will work.
6.But I want ‘old old new’ from the previous example.
- Just use the numeric modifier saying you want the third occurrence to be replaced. ’s/old/new/3‘ will work.
7.I wrote a rather complex sed script. How do I save and run it?
- Assuming that your file is named myscript1.sed, you can invoke sed -f myscript1.sed.
8.How do I delete trailing whitespaces from each line?
- sed ’s/[ \t]*$//’ Here we’re replacing any occurrence of a space or a tab with nothing. Check sed one-liners for more examples.
9.How do you print just a few first lines of the file?
- sed 1q will give you just the first line, sed 10q the first 10 lines.
10.How do you replace a pattern only if it’s found, so that it’s executed faster?
- Nest the replacement statement: sed ‘/old/ s/old/new/g’ file.txt
Linux command line
1.You need to see the last fifteen lines of the files dog, cat and horse. What command should you use?
tail -15 dog cat horse
The tail utility displays the end of a file. The -15 tells tail to display the last fifteen lines of each specified file.
2.Who owns the data dictionary?
The SYS user owns the data dictionary. The SYS and SYSTEM users are created when the database is created.
3.You routinely compress old log files. You now need to examine a log from two months ago. In order to view its contents without first having to decompress it, use the _________ utility.
zcat
The zcat utility allows you to examine the contents of a compressed file much the same way that cat displays a file.
4.You suspect that you have two commands with the same name as the command is not producing the expected results. What command can you use to determine the location of the command being run?
which
The which command searches your path until it finds a command that matches the command you are looking for and displays its full path.
5.You locate a command in the /bin directory but do not know what it does. What command can you use to determine its purpose.
whatis
The whatis command displays a summary line from the man page for the specified command.
6.You wish to create a link to the /data directory in bob’s home directory so you issue the command ln /data /home/bob/datalink but the command fails. What option should you use in this command line to be successful.
Use the -F option
In order to create a link to a directory, you must use the -F option.
7.When you issue the command ls -l, the first character of the resulting display represents the file’s ___________.
type
The first character of the permission block designates the type of file that is being displayed.
8.What utility can you use to show a dynamic listing of running processes? __________
top
The top utility shows a listing of all running processes that is dynamically updated.
9.Where is standard output usually directed?
to the screen or display
By default, your shell directs standard output to your screen or display.
10.You wish to restore the file memo.ben which was backed up in the tarfile MyBackup.tar. What command should you type?
tar xf MyBackup.tar memo.ben
This command uses the x switch to extract a file. Here the file memo.ben will be restored from the tarfile MyBackup.tar.
11.You need to view the contents of the tarfile called MyBackup.tar. What command would you use?
tar tf MyBackup.tar
The t switch tells tar to display the contents and the f modifier specifies which file to examine.
12.You want to create a compressed backup of the users’ home directories. What utility should you use?
tar
You can use the z modifier with tar to compress your archive at the same time as creating it.
13.What daemon is responsible for tracking events on your system?
syslogd
The syslogd daemon is responsible for tracking system information and saving it to specified log files.
14.You have a file called phonenos that is almost 4,000 lines long. What text filter can you use to split it into four pieces each 1,000 lines long?
split
The split text filter will divide files into equally sized pieces. The default length of each piece is 1,000 lines.
15.You would like to temporarily change your command line editor to be vi. What command should you type to change it?
set -o vi
The set command is used to assign environment variables. In this case, you are instructing your shell to assign vi as your command line editor. However, once you log off and log back in you will return to the previously defined command line editor.
16.What account is created when you install Linux?
root
Whenever you install Linux, only one user account is created. This is the superuser account also known as root.
17.What command should you use to check the number of files and disk space used and each user’s defined quotas?
repquota
The repquota command is used to get a report on the status of the quotas you have set including the amount of allocated space and amount of used space.
Unix admin questions
1.How do you list the files in an UNIX directory while also showing hidden files?
ls-al
2.How do you execute a UNIX command in the background?
&
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.
4->read
2->write
1->execute
root have full permission-> 777
777(4+2+1).
rwxrwxrwx–>means
first rwx –> user
second rwx–> group
third rwx –> other
777 means full permission.
apply permission
chmod 755
755 means–>
user have full permission
group&others have read and execute.
5.What is the difference between a soft link and a hard link?
Hard links create inode pointers to a files’ actual location and can only be created on the same filesystem
Soft links create an inode pointer to a file NAME and can be created to point to a file on ANOTHER filesystem.
6.Give the command to display space usage on the UNIX file system.
df -h
7.Explain iostat, vmstat and netstat.
iostat returns disk and other data i/o statistics
vmstat returns memory paging statistics, virtual and real
netsta returns network statistics. GENERALLY the first line or the command alone will return statistical
averages since boottime; the commands can also be run with flags to report instantaneous snapshots every x seconds for y results (ie vmstat 5 5 gives a snapshot every 5 seconds 5 times in a row
8.How would you change all occurrences of a value using VI?
%s/OLD/NEW/g
9.Give two UNIX kernel parameters that effect an Oracle install
shared memory and semaphores: shmmmax, shmmmin, etc and seminfo_semmsl (both affect the memory useage and sharing at the kernel level and usually a reboot is necessary for them to take affect safely (kernel parameters can be updated live on many Unix OS’s but is not recommended unless you are at the expert level and have performed the task before successfully on a sandbox)
10.Briefly, how do you install Oracle software on UNIX.
Oracle can be installed from CD or better yet from CD’s copied in their entirety to a hard disk simply with the “runInstall” script. a) make sure the filesystems you will be installing to have enough space AND no previous Oracle installation upon them and b) MUST be run as the Oracle user NOT root. (ie: you need to have an oracle user account created with the proper rwx rights to the installation target filesystem) c) several key variables such as hostname, some kernel parameters, and a few other pre-installation tasks need to be performed dependent upon the OS Oracle will be run upon.
Linux application programming questions
1.Explain the difference between a static library and a dynamic library?
Static library is linked into the executable, while a dynamic library (or shared object) is loaded while the executable has started.
2.How do you create a static library?
If you have a collection of object (.o) files, you can do it by running ar command. Generally a static library has a .a extension, and you can link it into an executable by providing -l libraryname to gcc.
3.Where should the developed libraries be installed on the system?
GNU recommends /usr/local/bin for binaries and /usr/local/lib for libraries.
4.What’s LD_LIBRARY_PATH?
It’s an environment variable that lists all the directories which should be searched for libraries before the standard directories are searched.
5.How do you create a shared library?
Create the object file with -fPIC for position-independent code, then run gcc with -shared option.
6.How do you install a shared library?
Run ldconfig in the standard directory that it’s installed in.
7.What does ldd do?
It shows a list of installed shared libraries.
8.How do you dynamically load a library in your app?
Use dlopen()
9.What does nm command do?
It reports the list of symbols in a given library.
Basic shell scripting questions
1.How do you find out what’s your shell? - echo $SHELL
2.What’s the command to find out today’s date? - date
3.What’s the command to find out users on the system? - who
4.How do you find out the current directory you’re in? - pwd
5.How do you remove a file? - rm
6.How do you remove a <="" b="">- rm -rf
7.How do you find out your own username? - whoami
8.How do you send a mail message to somebody? - mailsomebody@techinterviews.com -s ‘Your subject’ -c ‘cc@techinterviews.com‘
9.How do you count words, lines and characters in a file? - wc
10.How do you search for a string inside a given file? - grep string filename
11.How do you search for a string inside a directory? - grep string *
12.How do you search for a string in a directory with the subdirectories recursed? - grep -r string * or find / |xargs grep “string”
13.What are PIDs? - They are process IDs given to processes. A PID can vary from 0 to 65535.
14.How do you list currently running process? - ps
15.How do you stop a process? - kill pid
16.How do you find out about all running processes? - ps -ag
17.How do you stop all the processes, except the shell window? - kill 0
19.How do you refer to the arguments passed to a shell script? - $1, $2 and so on. $0 is your script name.
20.What’s the conditional statement in shell scripting? - if {condition} then … fi
21.How do you do number comparison in shell scripts? - -eq, -ne, -lt, -le, -gt, -ge
22.How do you test for file properties in shell scripts? - -s filename tells you if the file is not empty, -f filename tells you whether the argument is a file, and not a directory, -d filename tests if the argument is a directory, and not a file, -w filename tests for writeability, -r filename tests for readability, -x filename tests for executability
23.How do you do Boolean logic operators in shell scripting? - ! tests for logical not, -a tests for logical and, and -o tests for logical or.
24.How do you find out the number of arguments passed to the shell script? - $#
25.What’s a way to do multilevel if-else’s in shell scripting? - if {condition} then {statement} elif {condition} {statement} fi
26.How do you write a for loop in shell? - for {variable name} in {list} do {statement} done
27.How do you write a while loop in shell? - while {condition} do {statement} done
28.How does a case statement look in shell scripts? - case {variable} in {possible-value-1}) {statement};; {possible-value-2}) {statement};; esac
29.How do you read keyboard input in shell scripts? - read {variable-name}
30.How do you define a function in a shell script? - function-name() { #some code here return }
31.How does getopts command work? - The parameters to your script can be passed as -n 15 -x 20. Inside the script, you can iterate through the getopts array as while getopts n:x option, and the variable $option contains the value of the entered option.
Simple FreeBSD questions
1.What’s in the file /etc/ttys? - Configuration for virtual consoles for the startup. By default FreeBSD has 8 virtual consoles.
2.You’re told that the permissions of a file are 645. Quick, how do you calculate what it means? - The permissions value are always 4 for read, 2 for write, 1 for execute. The three numbers are always for owner, group, and everybody on the system. Therefore 645 means: owner - read and write, group - read only, everybody - read and execute.
3.Explain what each column means in the top command:
48630 techinterviews 2 0 29816K 9148K select 3:18 0.00% 0.00% navigator-linu
175 root 2 0 924K 252K select 1:41 0.00% 0.00% syslogd
7059 techinterviews 2 0 7260K 4644K poll 1:38 0.00% 0.00% mutt
The first column is the process id, followed by the username, followed by priority…
4.Explain the difference between SIGTERM and SIGKILL. SIGTERM asks the application to terminate in a polite way, it warns about the pending closure and asks the app to finish whatever it is doing. SIGKILL will kill the process no matter what. This is telling the application that it will be shut down no matter what.
5.Explain the difference between SIGHUP, SIGUSR1, and SIGUSR2. Those are application specific and therefore are not defined on the OS level.
6.How do you change your shell to bash?
% chsh -s /usr/local/bin/bash
Unix sysadmin interview questions
Q: How would you make the following SQL statement run faster? SELECT * FROM TABLEA WHERE COL1=’A’ AND COL2=’B';
A: Make sure that COL1 and COL2 have indexes.
Find out which condition will return less values and use that as the first conditonal.
Q: What is Data Mining
A: Data Minig is the process of sifting through extremeley large amounts of Data to find trends or relevent information.
Q: Name the Seven layers in the OSI Model.
A: Application, Presentation, Session, Transport, Network, Data Link, Physical
Q: What is one way to view a unix network share on a Windows computer, within explorer
A: NFS, The Unix computer can be running a NFS Server Daemon.
Q: How would you find all the processes running on your computer.
A: Unix, is ps -ef or ps -aux depending on version.
Q: What is DHCP
A: DHCP is a way to dynamically assign IP address to computers. Dynamic Host Configuration Protocol
Q: What is HTTP Tunneling
A: HTTP Tunneling is a security method that encrypts packets traveling through the internet. Only the intended recipient should be able to decrypt the packets. Can be used to Create Virtual Private Networks. (VPN)
Q: Scenario: You have 9 identical looking balls, however, one ball is heavier than the others. You have two chances to use a balance. How do you find out which ball is the heaviest?
A: Split into groups of three, randomly choose two groups and use the balance on them. If one group is heavier, then discard the other 6 balls. If the two groups are the same weight. The heavier ball must be in the group that was not on the scale. Now randomly choose two balls and test on balance. If they are the same weight, the heaviest ball is on one that was not tested. Else the heaviest ball is already known from the balance.
Unix/Linux programming interview questions
Question 1: What is the major advantage of a hash table? (Asked by Silicon Magic Corp. people)
Answer: The major advantage of a hash table is its speed. Because the hash function is to take a range of key values and transform them into index values in such a way that the key values are distributed randomly across all the indices of a hash table.
Question 2: What are the techniques that you use to handle the collisions in hash tables?(Asked by Silicon Magic Corp. people)
Answer: We can use two major techniques to handle the collisions. They are open addressing and separate chaining. In open addressing, data items that hash to a full array cell are placed in another cell in the array. In separate chaining, each array element consists of a linked list. All data items hashing to a given array index are inserted in that list.
Question 3: In Unix OS, what is the file server? (Asked by Silicon Magic Corp. people)
Answer: A file server is a machine that shares its disk storage and files with other machines on the network.
Question 4: What is NFS? What is its job?(Asked by Silicon Magic Corp. people)
Answer: NFS stands for Network File System. NFS enables filesystems physically residing on one computer system to be used by other computers in the network, appearing to users on the remote host as just another local disk.
Question 5: What is CVS? List some useful CVS commands.(Asked by Silicon Magic Corp.people)
Anser: CVS is Concurrent Version System. It is the front end to the RCS revision control system which extends the notion of revision control from a collection of files in a single directory to a hierarchical collection of directories consisting of revision controlled files. These directories and files can be combined together to form a software release.
There are some useful commands that are being used very often. They are
cvs checkout
cvs update
cvs add
cvs remove
cvs commit
Unix/Linux administration interview questions
What is LILO?
LILO stands for Linux boot loader. It will load the MBR, master boot record, into the memory, and tell the system which partition and hard drive to boot from.
What is the main advantage of creating links to a file instead of copies of the file?
A: The main advantage is not really that it saves disk space (though it does that too) but, rather, that a change of permissions on the file is applied to all the link access points. The link will show permissions of lrwxrwxrwx but that is for the link itself and not the access to the file to which the link points. Thus if you want to change the permissions for a command, such as su, you only have to do it on the original. With copies you have to find all of the copies and change permission on each of the copies.
Write a command to find all of the files which have been accessed within the last 30 days.
find / -type f -atime -30 > December.files
This command will find all the files under root, which is ‘/’, with file type is file. ‘-atime -30′ will give all the files accessed less than 30 days ago. And the output will put into a file call December.files.
What is the most graceful way to get to run level single user mode?
A: The most graceful way is to use the command init s.
If you want to shut everything down before going to single user mode then do init 0 first and from the ok prompt do a boot -s.
What does the following command line produce? Explain each aspect of this line.
$ (date ; ps -ef | awk ‘{print $1}’ | sort | uniq | wc -l ) >> Activity.log
A: First let’s dissect the line: The date gives the date and time as the first command of the line, this is followed by the a list of all running processes in long form with UIDs listed first, this is the ps -ef. These are fed into the awk which filters out all but the UIDs; these UIDs are piped into sort for no discernible reason and then onto uniq (now we see the reason for the sort - uniq only works on sorted data - if the list is A, B, A, then A, B, A will be the output of uniq, but if it’s A, A, B then A, B is the output) which produces only one copy of each UID.
These UIDs are fed into wc -l which counts the lines - in this case, the number of distinct UIDs running processes on the system. Finally, the results of these two commands, the date and the wc -l, are appended to the file "Activity.log". Now to answer the question as to what this command line produces. This writes the date and time into the file Activity.log together with the number of distinct users who have processes running on the system at that time. If the file already exists, then these items are appended to the file, otherwise, the file is created.
Networking questions
1.What is a default gateway?
- The exit-point from one network and entry-way into another network, often the router of the network.
2.How do you set a default route on an IOS Cisco router?
- ip route 0.0.0.0 0.0.0.0 x.x.x.x [where x.x.x.x represents the destination address]
3.What is the difference between a domain local group and a global group?
- Domain local groups grant permissions to objects within the domain in which the reside. Global groups contain grant permissions tree or forest-wide for any objects within the Active Directory.
4.What is LDAP used for?
- LDAP is a set of a protocol used for providing access to information directories.
5.What tool have you used to create and analyze packet captures?
- Network Monitor in Win2K / Win2K3, Ethereal in Linux, OptiView Series II (by Fluke Networks).
6.What is the significance of the IP address 255.255.255.255?
- The limited broadcast address is utilized when an IP node must perform a one-to-everyone delivery on the local network but the network ID is unknown.
Windows admin interview questions
1. Describe how the DHCP lease is obtained. It’s a four-step process consisting of (a) IP request, (b) IP offer, © IP selection and (d) acknowledgment.
2. I can’t seem to access the Internet, don’t have any access to the corporate network and on ipconfig my address is 169.254.*.*. What happened? The 169.254.*.* netmask is assigned to Windows machines running 98/2000/XP if the DHCP server is not available. The name for the technology is APIPA (Automatic Private Internet Protocol Addressing).
3. We’ve installed a new Windows-based DHCP server, however, the users do not seem to be getting DHCP leases off of it. The server must be authorized first with the Active Directory.
4. How can you force the client to give up the dhcp lease if you have access to the client PC? ipconfig /release
5. What authentication options do Windows 2000 Servers have for remote clients? PAP, SPAP, CHAP, MS-CHAP and EAP.
6. What are the networking protocol options for the Windows clients if for some reason you do not want to use TCP/IP? NWLink (Novell), NetBEUI, AppleTalk (Apple).
7. What is data link layer in the OSI reference model responsible for? Data link layer is located above the physical layer, but below the network layer. Taking raw data bits and packaging them into frames. The network layer will be responsible for addressing the frames, while the physical layer is responsible for retrieving and sending raw data bits.
8. What is binding order? The order by which the network protocols are used for client-server communications. The most frequently used protocols should be at the top.
9. How do cryptography-based keys ensure the validity of data transferred across the network? Each IP packet is assigned a checksum, so if the checksums do not match on both receiving and transmitting ends, the data was modified or corrupted.
10. Should we deploy IPSEC-based security or certificate-based security? They are really two different technologies. IPSec secures the TCP/IP communication and protects the integrity of the packets. Certificate-based security ensures the validity of authenticated clients and servers.
11. What is LMHOSTS file? It’s a file stored on a host machine that is used to resolve NetBIOS to specific IP addresses.
12. What’s the difference between forward lookup and reverse lookup in DNS?Forward lookup is name-to-address, the reverse lookup is address-to-name.
13. How can you recover a file encrypted using EFS? Use the domain recovery agent.
Networking and protocols interview questions
Q: What are the seven layers of the OSI model?
A: The layers are physical, data link, network, transport, session, presentation, and application layers.
Q: In the TCP client-server model, how does the three-way handshake work in opening connection?
A: The client first sends a packet with sequence "x" to the server. When the server receives this packet, the server will send back another packet with sequence "y", acknowledging the request of the client. When the client receives the acknowledgment from the server, the client will then send an acknowledge back to the server for acknowledging that sequence "y" has been received.
Q: What is the purpose of exchanging beginning sequence numbers during the connection in the TCP client-server model?
A: To ensure that any data lost during data transfer can be retransmitted.
Q: How does Asynchronous Transfer Mode (ATM) work?
A: ATM works by transmitting all traffic in small, fixed-size cells. These small, fixed-size cells reduce queuing delay and can be switched quickly. ATM fits into layer 2 of the OSI model and provides functions for framing and error correction. At the port interface, ATM switches convert cells into frames, and vice versa. ATM provides Quality of Service and traffic shaping.
Q: Given a Class B Network with a subnet mask of 255.255.248.0 and a packet addressed to 130.40.32.16, what is the subnet address?
A: Take the 2 addresses, write them in binary form, then AND them. The answer is 130.40.32.0
Networking and Unix interview questions
What is UTP?
UTP — Unshielded twisted pair 10BASE-T is the preferred Ethernet medium of the 90s. It is based on a star topology and provides a number of advantages over coaxial media:
It uses inexpensive, readily available copper phone wire. UTP wire is much easier to install and debug than coax. UTP uses RG-45 connectors, which are cheap and reliable.
What is a router? What is a gateway?
Routers are machines that direct a packet through the maze of networks that stand between its source and destination. Normally a router is used for internal networks while a gateway acts a door for the packet to reach the ‘outside’ of the internal network
What is Semaphore? What is deadlock?
Semaphore is a synchronization tool to solve a critical-section problem, can be used to control access to the critical section for a process or thread. The main disadvantage (same of mutual-exclusion) is require busy waiting. It will create problems in a multiprogramming system, where a single CPU is shared among many processes.
Busy waiting wastes CPU cycles.
Deadlock is a situation when two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes. The implementation of a semaphore with a waiting queue may result in this situation.
What is Virtual Memory?
Virtual memory is a technique that allows the execution of processes that may not be completely in memory. A separation of user logical memory from physical memory allows an extremely large virtual memory to be provided for programmers when only a smaller physical memory is available. It is commonly implemented by demand paging. A demand paging system is similar to a paging system with swapping. Processes reside on secondary memory (which is usually a disk). When we want to execute a process, we swap it into memory.
Explain the layered aspect of a UNIX system. What are the layers? What does it mean to say they are layers?
A UNIX system has essentially three main layers:
The hardware
The operating system kernel
The user-level programs
The kernel hides the system’s hardware underneath an abstract, high-level programming interface. It is responsible for implementing many of the facilities that users and user-level programs take for granted.
The kernel assembles all of the following UNIX concepts from lower-level hardware features:
Processes (time-sharing, protected address space
Signals and semaphores
Virtual Memory (swapping, paging, and mapping)
The filesystem (files, directories, namespace)
Pipes and network connections (inter-process communication)
1.What is sed? -
sed is stream editor, a Unix tool for working with streams of text data
2.How do you substitute strings with sed?
- Use ’s/old/new’ command, so sed ’s/hello/goodbye/’ would substitute the occurrence of the word hello to goodbye.
3.How do you inject text with sed?
- & in the substitution string defines the pattern found in the search string. As an example, here’s us trying to find a word ‘hello’ and replacing it with ‘hello and how are you’: echo ‘hello there’ | sed ’s/^hello/& and how are you/’
4.Can I find several patterns and refer to them in the replacement string?
- Yes, use (pattern) and then refer to your patterns as \1, \2, \3 and so on.
5.If the string is ‘old old old’ and I run ’s/old/new’, I get ‘new old old’ as the result. I need ‘new new new‘.
- You forgot the global modifier, which would replace every occurrence of the pattern with the substitution. ’s/old/new/g‘ will work.
6.But I want ‘old old new’ from the previous example.
- Just use the numeric modifier saying you want the third occurrence to be replaced. ’s/old/new/3‘ will work.
7.I wrote a rather complex sed script. How do I save and run it?
- Assuming that your file is named myscript1.sed, you can invoke sed -f myscript1.sed.
8.How do I delete trailing whitespaces from each line?
- sed ’s/[ \t]*$//’ Here we’re replacing any occurrence of a space or a tab with nothing. Check sed one-liners for more examples.
9.How do you print just a few first lines of the file?
- sed 1q will give you just the first line, sed 10q the first 10 lines.
10.How do you replace a pattern only if it’s found, so that it’s executed faster?
- Nest the replacement statement: sed ‘/old/ s/old/new/g’ file.txt
Linux command line
1.You need to see the last fifteen lines of the files dog, cat and horse. What command should you use?
tail -15 dog cat horse
The tail utility displays the end of a file. The -15 tells tail to display the last fifteen lines of each specified file.
2.Who owns the data dictionary?
The SYS user owns the data dictionary. The SYS and SYSTEM users are created when the database is created.
3.You routinely compress old log files. You now need to examine a log from two months ago. In order to view its contents without first having to decompress it, use the _________ utility.
zcat
The zcat utility allows you to examine the contents of a compressed file much the same way that cat displays a file.
4.You suspect that you have two commands with the same name as the command is not producing the expected results. What command can you use to determine the location of the command being run?
which
The which command searches your path until it finds a command that matches the command you are looking for and displays its full path.
5.You locate a command in the /bin directory but do not know what it does. What command can you use to determine its purpose.
whatis
The whatis command displays a summary line from the man page for the specified command.
6.You wish to create a link to the /data directory in bob’s home directory so you issue the command ln /data /home/bob/datalink but the command fails. What option should you use in this command line to be successful.
Use the -F option
In order to create a link to a directory, you must use the -F option.
7.When you issue the command ls -l, the first character of the resulting display represents the file’s ___________.
type
The first character of the permission block designates the type of file that is being displayed.
8.What utility can you use to show a dynamic listing of running processes? __________
top
The top utility shows a listing of all running processes that is dynamically updated.
9.Where is standard output usually directed?
to the screen or display
By default, your shell directs standard output to your screen or display.
10.You wish to restore the file memo.ben which was backed up in the tarfile MyBackup.tar. What command should you type?
tar xf MyBackup.tar memo.ben
This command uses the x switch to extract a file. Here the file memo.ben will be restored from the tarfile MyBackup.tar.
11.You need to view the contents of the tarfile called MyBackup.tar. What command would you use?
tar tf MyBackup.tar
The t switch tells tar to display the contents and the f modifier specifies which file to examine.
12.You want to create a compressed backup of the users’ home directories. What utility should you use?
tar
You can use the z modifier with tar to compress your archive at the same time as creating it.
13.What daemon is responsible for tracking events on your system?
syslogd
The syslogd daemon is responsible for tracking system information and saving it to specified log files.
14.You have a file called phonenos that is almost 4,000 lines long. What text filter can you use to split it into four pieces each 1,000 lines long?
split
The split text filter will divide files into equally sized pieces. The default length of each piece is 1,000 lines.
15.You would like to temporarily change your command line editor to be vi. What command should you type to change it?
set -o vi
The set command is used to assign environment variables. In this case, you are instructing your shell to assign vi as your command line editor. However, once you log off and log back in you will return to the previously defined command line editor.
16.What account is created when you install Linux?
root
Whenever you install Linux, only one user account is created. This is the superuser account also known as root.
17.What command should you use to check the number of files and disk space used and each user’s defined quotas?
repquota
The repquota command is used to get a report on the status of the quotas you have set including the amount of allocated space and amount of used space.
Unix admin questions
1.How do you list the files in an UNIX directory while also showing hidden files?
ls-al
2.How do you execute a UNIX command in the background?
&
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.
4->read
2->write
1->execute
root have full permission-> 777
777(4+2+1).
rwxrwxrwx–>means
first rwx –> user
second rwx–> group
third rwx –> other
777 means full permission.
apply permission
chmod 755
755 means–>
user have full permission
group&others have read and execute.
5.What is the difference between a soft link and a hard link?
Hard links create inode pointers to a files’ actual location and can only be created on the same filesystem
Soft links create an inode pointer to a file NAME and can be created to point to a file on ANOTHER filesystem.
6.Give the command to display space usage on the UNIX file system.
df -h
7.Explain iostat, vmstat and netstat.
iostat returns disk and other data i/o statistics
vmstat returns memory paging statistics, virtual and real
netsta returns network statistics. GENERALLY the first line or the command alone will return statistical
averages since boottime; the commands can also be run with flags to report instantaneous snapshots every x seconds for y results (ie vmstat 5 5 gives a snapshot every 5 seconds 5 times in a row
8.How would you change all occurrences of a value using VI?
%s/OLD/NEW/g
9.Give two UNIX kernel parameters that effect an Oracle install
shared memory and semaphores: shmmmax, shmmmin, etc and seminfo_semmsl (both affect the memory useage and sharing at the kernel level and usually a reboot is necessary for them to take affect safely (kernel parameters can be updated live on many Unix OS’s but is not recommended unless you are at the expert level and have performed the task before successfully on a sandbox)
10.Briefly, how do you install Oracle software on UNIX.
Oracle can be installed from CD or better yet from CD’s copied in their entirety to a hard disk simply with the “runInstall” script. a) make sure the filesystems you will be installing to have enough space AND no previous Oracle installation upon them and b) MUST be run as the Oracle user NOT root. (ie: you need to have an oracle user account created with the proper rwx rights to the installation target filesystem) c) several key variables such as hostname, some kernel parameters, and a few other pre-installation tasks need to be performed dependent upon the OS Oracle will be run upon.
Linux application programming questions
1.Explain the difference between a static library and a dynamic library?
Static library is linked into the executable, while a dynamic library (or shared object) is loaded while the executable has started.
2.How do you create a static library?
If you have a collection of object (.o) files, you can do it by running ar command. Generally a static library has a .a extension, and you can link it into an executable by providing -l libraryname to gcc.
3.Where should the developed libraries be installed on the system?
GNU recommends /usr/local/bin for binaries and /usr/local/lib for libraries.
4.What’s LD_LIBRARY_PATH?
It’s an environment variable that lists all the directories which should be searched for libraries before the standard directories are searched.
5.How do you create a shared library?
Create the object file with -fPIC for position-independent code, then run gcc with -shared option.
6.How do you install a shared library?
Run ldconfig in the standard directory that it’s installed in.
7.What does ldd do?
It shows a list of installed shared libraries.
8.How do you dynamically load a library in your app?
Use dlopen()
9.What does nm command do?
It reports the list of symbols in a given library.
Basic shell scripting questions
1.How do you find out what’s your shell? - echo $SHELL
2.What’s the command to find out today’s date? - date
3.What’s the command to find out users on the system? - who
4.How do you find out the current directory you’re in? - pwd
5.How do you remove a file? - rm
6.How do you remove a <="" b="">- rm -rf
7.How do you find out your own username? - whoami
8.How do you send a mail message to somebody? - mailsomebody@techinterviews.com -s ‘Your subject’ -c ‘cc@techinterviews.com‘
9.How do you count words, lines and characters in a file? - wc
10.How do you search for a string inside a given file? - grep string filename
11.How do you search for a string inside a directory? - grep string *
12.How do you search for a string in a directory with the subdirectories recursed? - grep -r string * or find / |xargs grep “string”
13.What are PIDs? - They are process IDs given to processes. A PID can vary from 0 to 65535.
14.How do you list currently running process? - ps
15.How do you stop a process? - kill pid
16.How do you find out about all running processes? - ps -ag
17.How do you stop all the processes, except the shell window? - kill 0
19.How do you refer to the arguments passed to a shell script? - $1, $2 and so on. $0 is your script name.
20.What’s the conditional statement in shell scripting? - if {condition} then … fi
21.How do you do number comparison in shell scripts? - -eq, -ne, -lt, -le, -gt, -ge
22.How do you test for file properties in shell scripts? - -s filename tells you if the file is not empty, -f filename tells you whether the argument is a file, and not a directory, -d filename tests if the argument is a directory, and not a file, -w filename tests for writeability, -r filename tests for readability, -x filename tests for executability
23.How do you do Boolean logic operators in shell scripting? - ! tests for logical not, -a tests for logical and, and -o tests for logical or.
24.How do you find out the number of arguments passed to the shell script? - $#
25.What’s a way to do multilevel if-else’s in shell scripting? - if {condition} then {statement} elif {condition} {statement} fi
26.How do you write a for loop in shell? - for {variable name} in {list} do {statement} done
27.How do you write a while loop in shell? - while {condition} do {statement} done
28.How does a case statement look in shell scripts? - case {variable} in {possible-value-1}) {statement};; {possible-value-2}) {statement};; esac
29.How do you read keyboard input in shell scripts? - read {variable-name}
30.How do you define a function in a shell script? - function-name() { #some code here return }
31.How does getopts command work? - The parameters to your script can be passed as -n 15 -x 20. Inside the script, you can iterate through the getopts array as while getopts n:x option, and the variable $option contains the value of the entered option.
Simple FreeBSD questions
1.What’s in the file /etc/ttys? - Configuration for virtual consoles for the startup. By default FreeBSD has 8 virtual consoles.
2.You’re told that the permissions of a file are 645. Quick, how do you calculate what it means? - The permissions value are always 4 for read, 2 for write, 1 for execute. The three numbers are always for owner, group, and everybody on the system. Therefore 645 means: owner - read and write, group - read only, everybody - read and execute.
3.Explain what each column means in the top command:
48630 techinterviews 2 0 29816K 9148K select 3:18 0.00% 0.00% navigator-linu
175 root 2 0 924K 252K select 1:41 0.00% 0.00% syslogd
7059 techinterviews 2 0 7260K 4644K poll 1:38 0.00% 0.00% mutt
The first column is the process id, followed by the username, followed by priority…
4.Explain the difference between SIGTERM and SIGKILL. SIGTERM asks the application to terminate in a polite way, it warns about the pending closure and asks the app to finish whatever it is doing. SIGKILL will kill the process no matter what. This is telling the application that it will be shut down no matter what.
5.Explain the difference between SIGHUP, SIGUSR1, and SIGUSR2. Those are application specific and therefore are not defined on the OS level.
6.How do you change your shell to bash?
% chsh -s /usr/local/bin/bash
Unix sysadmin interview questions
Q: How would you make the following SQL statement run faster? SELECT * FROM TABLEA WHERE COL1=’A’ AND COL2=’B';
A: Make sure that COL1 and COL2 have indexes.
Find out which condition will return less values and use that as the first conditonal.
Q: What is Data Mining
A: Data Minig is the process of sifting through extremeley large amounts of Data to find trends or relevent information.
Q: Name the Seven layers in the OSI Model.
A: Application, Presentation, Session, Transport, Network, Data Link, Physical
Q: What is one way to view a unix network share on a Windows computer, within explorer
A: NFS, The Unix computer can be running a NFS Server Daemon.
Q: How would you find all the processes running on your computer.
A: Unix, is ps -ef or ps -aux depending on version.
Q: What is DHCP
A: DHCP is a way to dynamically assign IP address to computers. Dynamic Host Configuration Protocol
Q: What is HTTP Tunneling
A: HTTP Tunneling is a security method that encrypts packets traveling through the internet. Only the intended recipient should be able to decrypt the packets. Can be used to Create Virtual Private Networks. (VPN)
Q: Scenario: You have 9 identical looking balls, however, one ball is heavier than the others. You have two chances to use a balance. How do you find out which ball is the heaviest?
A: Split into groups of three, randomly choose two groups and use the balance on them. If one group is heavier, then discard the other 6 balls. If the two groups are the same weight. The heavier ball must be in the group that was not on the scale. Now randomly choose two balls and test on balance. If they are the same weight, the heaviest ball is on one that was not tested. Else the heaviest ball is already known from the balance.
Unix/Linux programming interview questions
Question 1: What is the major advantage of a hash table? (Asked by Silicon Magic Corp. people)
Answer: The major advantage of a hash table is its speed. Because the hash function is to take a range of key values and transform them into index values in such a way that the key values are distributed randomly across all the indices of a hash table.
Question 2: What are the techniques that you use to handle the collisions in hash tables?(Asked by Silicon Magic Corp. people)
Answer: We can use two major techniques to handle the collisions. They are open addressing and separate chaining. In open addressing, data items that hash to a full array cell are placed in another cell in the array. In separate chaining, each array element consists of a linked list. All data items hashing to a given array index are inserted in that list.
Question 3: In Unix OS, what is the file server? (Asked by Silicon Magic Corp. people)
Answer: A file server is a machine that shares its disk storage and files with other machines on the network.
Question 4: What is NFS? What is its job?(Asked by Silicon Magic Corp. people)
Answer: NFS stands for Network File System. NFS enables filesystems physically residing on one computer system to be used by other computers in the network, appearing to users on the remote host as just another local disk.
Question 5: What is CVS? List some useful CVS commands.(Asked by Silicon Magic Corp.people)
Anser: CVS is Concurrent Version System. It is the front end to the RCS revision control system which extends the notion of revision control from a collection of files in a single directory to a hierarchical collection of directories consisting of revision controlled files. These directories and files can be combined together to form a software release.
There are some useful commands that are being used very often. They are
cvs checkout
cvs update
cvs add
cvs remove
cvs commit
Unix/Linux administration interview questions
What is LILO?
LILO stands for Linux boot loader. It will load the MBR, master boot record, into the memory, and tell the system which partition and hard drive to boot from.
What is the main advantage of creating links to a file instead of copies of the file?
A: The main advantage is not really that it saves disk space (though it does that too) but, rather, that a change of permissions on the file is applied to all the link access points. The link will show permissions of lrwxrwxrwx but that is for the link itself and not the access to the file to which the link points. Thus if you want to change the permissions for a command, such as su, you only have to do it on the original. With copies you have to find all of the copies and change permission on each of the copies.
Write a command to find all of the files which have been accessed within the last 30 days.
find / -type f -atime -30 > December.files
This command will find all the files under root, which is ‘/’, with file type is file. ‘-atime -30′ will give all the files accessed less than 30 days ago. And the output will put into a file call December.files.
What is the most graceful way to get to run level single user mode?
A: The most graceful way is to use the command init s.
If you want to shut everything down before going to single user mode then do init 0 first and from the ok prompt do a boot -s.
What does the following command line produce? Explain each aspect of this line.
$ (date ; ps -ef | awk ‘{print $1}’ | sort | uniq | wc -l ) >> Activity.log
A: First let’s dissect the line: The date gives the date and time as the first command of the line, this is followed by the a list of all running processes in long form with UIDs listed first, this is the ps -ef. These are fed into the awk which filters out all but the UIDs; these UIDs are piped into sort for no discernible reason and then onto uniq (now we see the reason for the sort - uniq only works on sorted data - if the list is A, B, A, then A, B, A will be the output of uniq, but if it’s A, A, B then A, B is the output) which produces only one copy of each UID.
These UIDs are fed into wc -l which counts the lines - in this case, the number of distinct UIDs running processes on the system. Finally, the results of these two commands, the date and the wc -l, are appended to the file "Activity.log". Now to answer the question as to what this command line produces. This writes the date and time into the file Activity.log together with the number of distinct users who have processes running on the system at that time. If the file already exists, then these items are appended to the file, otherwise, the file is created.
Networking questions
1.What is a default gateway?
- The exit-point from one network and entry-way into another network, often the router of the network.
2.How do you set a default route on an IOS Cisco router?
- ip route 0.0.0.0 0.0.0.0 x.x.x.x [where x.x.x.x represents the destination address]
3.What is the difference between a domain local group and a global group?
- Domain local groups grant permissions to objects within the domain in which the reside. Global groups contain grant permissions tree or forest-wide for any objects within the Active Directory.
4.What is LDAP used for?
- LDAP is a set of a protocol used for providing access to information directories.
5.What tool have you used to create and analyze packet captures?
- Network Monitor in Win2K / Win2K3, Ethereal in Linux, OptiView Series II (by Fluke Networks).
6.What is the significance of the IP address 255.255.255.255?
- The limited broadcast address is utilized when an IP node must perform a one-to-everyone delivery on the local network but the network ID is unknown.
Windows admin interview questions
1. Describe how the DHCP lease is obtained. It’s a four-step process consisting of (a) IP request, (b) IP offer, © IP selection and (d) acknowledgment.
2. I can’t seem to access the Internet, don’t have any access to the corporate network and on ipconfig my address is 169.254.*.*. What happened? The 169.254.*.* netmask is assigned to Windows machines running 98/2000/XP if the DHCP server is not available. The name for the technology is APIPA (Automatic Private Internet Protocol Addressing).
3. We’ve installed a new Windows-based DHCP server, however, the users do not seem to be getting DHCP leases off of it. The server must be authorized first with the Active Directory.
4. How can you force the client to give up the dhcp lease if you have access to the client PC? ipconfig /release
5. What authentication options do Windows 2000 Servers have for remote clients? PAP, SPAP, CHAP, MS-CHAP and EAP.
6. What are the networking protocol options for the Windows clients if for some reason you do not want to use TCP/IP? NWLink (Novell), NetBEUI, AppleTalk (Apple).
7. What is data link layer in the OSI reference model responsible for? Data link layer is located above the physical layer, but below the network layer. Taking raw data bits and packaging them into frames. The network layer will be responsible for addressing the frames, while the physical layer is responsible for retrieving and sending raw data bits.
8. What is binding order? The order by which the network protocols are used for client-server communications. The most frequently used protocols should be at the top.
9. How do cryptography-based keys ensure the validity of data transferred across the network? Each IP packet is assigned a checksum, so if the checksums do not match on both receiving and transmitting ends, the data was modified or corrupted.
10. Should we deploy IPSEC-based security or certificate-based security? They are really two different technologies. IPSec secures the TCP/IP communication and protects the integrity of the packets. Certificate-based security ensures the validity of authenticated clients and servers.
11. What is LMHOSTS file? It’s a file stored on a host machine that is used to resolve NetBIOS to specific IP addresses.
12. What’s the difference between forward lookup and reverse lookup in DNS?Forward lookup is name-to-address, the reverse lookup is address-to-name.
13. How can you recover a file encrypted using EFS? Use the domain recovery agent.
Networking and protocols interview questions
Q: What are the seven layers of the OSI model?
A: The layers are physical, data link, network, transport, session, presentation, and application layers.
Q: In the TCP client-server model, how does the three-way handshake work in opening connection?
A: The client first sends a packet with sequence "x" to the server. When the server receives this packet, the server will send back another packet with sequence "y", acknowledging the request of the client. When the client receives the acknowledgment from the server, the client will then send an acknowledge back to the server for acknowledging that sequence "y" has been received.
Q: What is the purpose of exchanging beginning sequence numbers during the connection in the TCP client-server model?
A: To ensure that any data lost during data transfer can be retransmitted.
Q: How does Asynchronous Transfer Mode (ATM) work?
A: ATM works by transmitting all traffic in small, fixed-size cells. These small, fixed-size cells reduce queuing delay and can be switched quickly. ATM fits into layer 2 of the OSI model and provides functions for framing and error correction. At the port interface, ATM switches convert cells into frames, and vice versa. ATM provides Quality of Service and traffic shaping.
Q: Given a Class B Network with a subnet mask of 255.255.248.0 and a packet addressed to 130.40.32.16, what is the subnet address?
A: Take the 2 addresses, write them in binary form, then AND them. The answer is 130.40.32.0
Networking and Unix interview questions
What is UTP?
UTP — Unshielded twisted pair 10BASE-T is the preferred Ethernet medium of the 90s. It is based on a star topology and provides a number of advantages over coaxial media:
It uses inexpensive, readily available copper phone wire. UTP wire is much easier to install and debug than coax. UTP uses RG-45 connectors, which are cheap and reliable.
What is a router? What is a gateway?
Routers are machines that direct a packet through the maze of networks that stand between its source and destination. Normally a router is used for internal networks while a gateway acts a door for the packet to reach the ‘outside’ of the internal network
What is Semaphore? What is deadlock?
Semaphore is a synchronization tool to solve a critical-section problem, can be used to control access to the critical section for a process or thread. The main disadvantage (same of mutual-exclusion) is require busy waiting. It will create problems in a multiprogramming system, where a single CPU is shared among many processes.
Busy waiting wastes CPU cycles.
Deadlock is a situation when two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes. The implementation of a semaphore with a waiting queue may result in this situation.
What is Virtual Memory?
Virtual memory is a technique that allows the execution of processes that may not be completely in memory. A separation of user logical memory from physical memory allows an extremely large virtual memory to be provided for programmers when only a smaller physical memory is available. It is commonly implemented by demand paging. A demand paging system is similar to a paging system with swapping. Processes reside on secondary memory (which is usually a disk). When we want to execute a process, we swap it into memory.
Explain the layered aspect of a UNIX system. What are the layers? What does it mean to say they are layers?
A UNIX system has essentially three main layers:
The hardware
The operating system kernel
The user-level programs
The kernel hides the system’s hardware underneath an abstract, high-level programming interface. It is responsible for implementing many of the facilities that users and user-level programs take for granted.
The kernel assembles all of the following UNIX concepts from lower-level hardware features:
Processes (time-sharing, protected address space
Signals and semaphores
Virtual Memory (swapping, paging, and mapping)
The filesystem (files, directories, namespace)
Pipes and network connections (inter-process communication)
No comments:
Post a Comment