0% found this document useful (0 votes)
184 views

Linux Admin Interview Questions1

The document discusses the differences between scripting languages and programming languages. While traditionally there was a distinction, modern languages blur the lines. Scripting languages are easy to learn, interpreted, and run within another program. Programming languages are compiled and run independently. However, popular languages like Java and C# run within a virtual machine, similar to scripting languages. Today, the difference is largely academic as scripting languages can build complex software and have performance comparable to compiled languages.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
184 views

Linux Admin Interview Questions1

The document discusses the differences between scripting languages and programming languages. While traditionally there was a distinction, modern languages blur the lines. Scripting languages are easy to learn, interpreted, and run within another program. Programming languages are compiled and run independently. However, popular languages like Java and C# run within a virtual machine, similar to scripting languages. Today, the difference is largely academic as scripting languages can build complex software and have performance comparable to compiled languages.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 53

Interview questions for Linux admin 1. Advantages/disadvantages of script vs compiled program. Scripting vs. programming: is there a difference?

The short answer: These days, the line between a scripting language and a programming language is blurred. As such, in practical application, the differences are meaningless. So the answer is: no. Some details what a nerd might tell you: Scripting or writing scripts, is programming within a program. Traditionally you would write scripts to automate certain functionality within another program. Traditionally scripts would have very specific task like for example: reading a text file to extract all the email addresses. Why use a scripting language?

Easy to learn - compared to traditional programming languages. It takes much less code to do something with scripting than when using a traditional programming language.

Another characteristic of a scripting language, is that they are processed from scratch every time you run them. A nerd would say: scripting languages are not compiled. What is a compiled language? A compiled language (like Java and C,) are processed once (think of a food processor) and reduced (if you will,) to a simpler form that allows it to run faster than a script that has to be reprocessed every time. - MORE ABOUT PROGRAMMING LANGUAGES With programming, you are writing software that runs independent of an exterior (or parent) program. Also, when people would say they were programming, they were usually involved in some project that produced much more functionality than a traditional script. Things have changed I keep saying traditionally because the lines between scripting and programming are very blurred these days - scripting is now very powerful and is doing the work that once belonged to the realm of full blown programming - in a traditional sense.

Lets look at some examples: PHP: People refer to software written in PHP as scripts because PHP runs inside another program - the PHP script engine. But unlike traditional simple scripts, PHP software can be very complex and very powerful. Java: Most people would refer to Java as a full-blown programming language because its compiled. But, Java (like PHP) runs inside another program, something called the Java Virtual Machine. So here we see the first of those blurry lines I mentioned above. To summarize:

Scripting languages run inside another program. Scripting languages are not compiled. Scripting languages are easy to use and easy to write.

but

Very popular programming languages (Java, C#) run inside a parent program - like scripting languages. Scripting languages today are used to build complex software. Computers are so fast these days, and scripting languages are so efficient, that for most business operations, there is no practical speed advantage (that there once was,) with a compiled programming language.

Conclusion Today the difference between scripting and programming is largely and academic thing. You shouldnt have to concern yourself with what broad category a particular language may fall in.

2.

Which tool would you use to update Debian / Slackware / RedHat / Mandrake / SuSE ? To To To To update update update update the tool is debian apt-get update redhat we use up2date --nox configure slackware we use slackpkg update SuSE we use YaST

To update Mandrake we use The syntax for using rsync in this fashion looks like: rsync -switches --options [host]::[rsyncmodule/path/srcfile] [destination] 3. What does route command do?

Route manipulates the kernel's IP routing tables. Its primary use is to set up static routes to specific hosts or networks via an interface after it has been configured with the ifconfig(8) program. When the add or del options are used, route modifies the routing tables. Without these options, route displays the current contents of the routing tables. Differences between iptables and ipchains At first glance, ipchains and iptables appear to be quite similar. After all, both methods of packet filtering use chains of rules operating within the Linux kernel to decide not only which packets to let in or out, but also what to do with packets that match certain rules, however, iptables offer a much more extensible way of filtering packets, giving an administrator a finer grained level of control without building too much complexity into the entire system. Specifically, users comfortable with ipchains should be aware of the following significant differences between ipchains and iptables before attempting to use iptables:

Under iptables, each filtered packet is only processed using rules from one chain rather than multiple chains. In other words, a FORWARD packet coming into a system using ipchains would have to go through the INPUT, FORWARD, and OUTPUT chains in order to move along to its destination. However, iptables only sends packets to the INPUT chain if they are destined for the local system and only sends them to the OUTPUT chain if the local system generated the packets. For this reason, you must be sure to place the rule designed to catch a particular packet in the correct chain that will actually see the packet. The advantage is that you now have finer-grained control over the disposition of each packet. If you are attempting to block access to a particular website, it is now possible to block access attempts from clients running on hosts which use your host as a gateway. An OUTPUT rule which denies access will no longer prevent access for hosts which use your host as a gateway.

The DENY target has been changed to DROP. In ipchains, packets that matched a rule in a chain could be directed to the DENY target, which silently dropped the packet. This target must be changed to DROP in iptables to have the same effect. Order matters when placing options in a chain rule. Previously, with ipchains, it did not matter very much how you ordered the rule options when typing the rule. The iptables command is a bit pickier about where some options may go. For example, you must now specify the source or destination port after the protocol (ICMP, TCP, or UDP) to be used in a chain's rule.

When specifying network interfaces to be used with a rule, you must only use incoming interfaces (-i option) with INPUT or FORWARD chains and outgoing interfaces (-o option) with FORWARD or OUTPUT chains. This is necessary due to the fact that OUTPUT chains are no longer used by incoming interfaces, and INPUT chains are not seen by packets moving through outgoing interfaces. Whats eth0, ppp0, wlan0, ttyS0, etc.

4.

Loopback: lo Ethernet: eth0, eth1, ... Wi-Fi: wlan0, wlan1, wifi0, . Token Ring: tr0, tr1, ... PPP: ppp0, ppp1, ... 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 lets 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 its 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.

Solaris interview questions List the files in current directory sorted by size ? - ls -l | grep ^- | sort -nr List the hidden files in current directory ? - ls -a1 | grep "^\."

Delete blank lines in a file ? - cat sample.txt | grep -v ^$ > new_sample.txt Search for a sample string in particular files ? - grep .Debug. *.confHere grep uses the string .Debug. to search in all files with extension..conf. under current directory. Display the last newly appending lines of a file during appendingdata to the same file by some processes ? - tail .f Debug.logHere tail shows the newly appended data into Debug.log by some processes/user. Display the Disk Usage of file sizes under each directory in currentDirectory ? - du -k * | sort .nr (or) du .k . | sort -nr Change to a directory, which is having very long name ? - cd CDMA_3X_GEN*Here original directory name is . .CDMA_3X_GENERATION_DATA.. Display the all files recursively with path under current directory ? - find . -depth -print Set the Display automatically for the current new user ? - export DISPLAY=`eval who am i | cut -d"(" -f2 | cut -d")" -f1`Here in above command, see single quote, double quote, grave ascent is used. Observe carefully. Display the processes, which are running under yourusername ? - ps .aef | grep MaheshvjHere, Maheshvj is the username. List some Hot Keys for bash shell ? - Ctrl+l . Clears the Screen. Ctrl+r . Does a search in previously given commands in shell. Ctrl+u - Clears the typing before the hotkey. Ctrl+a . Places cursor at the beginning of the command at shell. Ctrl+e . Places cursor at the end of the command at shell. Ctrl+d . Kills the shell. Ctrl+z . Places the currently running process into background. Display the files in the directory by file size ?

- ls .ltr | sort .nr .k 5 How to save man pages to a file ? - man <command> | col .b > <output-file>Example : man top | col .b > top_help.txt How to know the date & time for . when script is executed ? - Add the following script line in shell script.eval echo "Script is executed at `date`" >> timeinfo.infHere, .timeinfo.inf. contains date & time details ie., when script is executed and history related to execution. How do you find out drive statistics ? - iostat -E Display disk usage in Kilobytes ? - du -k Display top ten largest files/directories ? - du -sk * | sort -nr | head How much space is used for users in kilobytes ? - quot -af How to create null file ? - cat /dev/null > filename1 Access common commands quicker ? - ps -ef | grep -i $@ Display the page size of memory ? - pagesize -a Display Ethernet Address arp table ? - arp -a Display the no.of active established connections to localhost ? - netstat -a | grep EST

Display the state of interfaces used for TCP/IP traffice ? - netstat -i Display the parent/child tree of a process ? - ptree <pid> Example: ptree 1267 Show the working directory of a process ? - pwdx <pid> Example: pwdx 1267 Display the processes current open files ? - pfiles <pid> Example: pfiles 1267 Display the inter-process communication facility status ? - ipcs Display the top most process utilizing most CPU ? - top .b 1 Alternative for top command ? - prstat -a

17.

What can be wrong with setuid scripts? If the script begins "#!/bin/sh" and a link (symbolic or otherwise) can be made to it with the name "-i", a setuid shell can be immediately obtained because the script will be invoked: "#!/bin/sh -i", ie: an interactive shell. Many kernels suffer from a race condition which can allow you to exchange the shellscript for another executable of your choice between the times that the newly exec()ed process goes setuid, and when the command interpreter gets started up. If you are persistent enough, in theory you could get the kernel to run any program you want. The IFS bug: the IFS shell variable contains a list of characters to be treated like whitespace by a shell when parsing command names. By changing the IFS variable to contain the "/" character, the command "/bin/true" becomes "bin true". All you need do is export the modified IFS variable, install a

command called "bin" in your path, and run a setuid script which calls "/bin/true". Then "bin" will be executed whilst setuid.

18.

What value does spawn return? Ans: Process ID How do you create a swapfile? # mkdir /files # mkfile 100m /files/swapfile # swap -a /files/swapfile # vi /etc/vfstab (An entry is added for the swap file): /files/swapfile swap no # swap l
Another method (redhat)

24.

$ dd if=/dev/zero of=/extra-swap bs=1024 $ mkswap /extra-swap 1024


count=1024

75. 76. Given the following pathname: $ /business/acctg/payable/supplier/april a) If you were in the directory called acctg, what would be the relative pathname name for the file called april? b) What would be the absolute pathname for april? 77. Suppose your directory had the following files: help. 1 help.2 help.3 help.4 help.O1 help.O2 aid.O1 aid.O2 aid.O3 back. 1 back.2 back.3 a) What is the command to list all files ending in 2? b) What is the command to list all files starting in aid? c) What is the command to list all "help" files with one character extension? What are two subtle differences in using the more and the pg commands? When is it better to use the more command rather than cat command?

78. 79.

80. 81. 82.

What are two functions the move mv command can carry out? Name two methods you could use to rename a file. The soccer league consists of boy and girl teams. The boy file names begin with B, the girl teams begin with G. All of these files are in one directory called "soccer", which is your current directory: Bteam.abc Bteam.OOl Bteam.OO2 Bteam.OO4 Gteam.win Gteam.OOl Gteam.OO2 Gteam.OO3 Write the commands to do the following: a) rename the file Bteam.abc to Bteam.OO3. b) erase the file Gteam. win after you have viewed the contents of the file c) make a directory for the boy team files called "boys", and one for the girl team files called" girls" d) move all the boy teams into the "boys" directory e) move all the girl teams into the "girls" directory f) make a new file called Gteam.OO4 that is identical to Gteam.OOl g) make a new file called Gteam.OO5 that is identical to Bteam.OO2

83. 84.

Draw a picture of the final directory structure for the "soccer" directory, showing all the files and directories. What metacharacter is used to do the following: 1.1 Move up one level higher in the directory tree structure 1.2 1.3 1.4 1.5 Specify all the files ending in .txt Specify one character Redirect input from a file Redirect the output and append it to a file

85. 86.

Which of the quoting or escape characters allows the dollar sign ($) to retain its special meaning? What is a faster way to do the same command? mv fileO.txt newdir mv filel.txt newdir mv file2.txt newdir mv file3.txt newdir List two ways to create a new file: What is the difference between > and >> operators? Write the command to do the following:

87. 88. 89.

1 Redirect the output from the directory listing to a printer. 2 Add the file efg.txt to the end of the file abc.txt. 3 The file testdata feeds information into the file called program 4 Observe the contents of the file called xyz.txt using MORE. 5 Observe a directory listing that is fo 90. 91. 92. 93. 94. 95. 96. 97. How do you estimate file space usage? How can you see all mounted drives? How can you find a path to the file in the system? What Linux HotKeys do you know? What can you tell about the tar Command? What types of files you know? How to copy files from on PC to another on the same network? Please describe information below: -rw-rw-r-- 1 dotpc dotpc 102 Jul 18 2003 file.buf drwxr-xr-x 9 dotpc dotpc 4096 Oct 21 09:34 bin lrwxrwxrwx 1 dotpc dotpc 20 Mar 21 15:00 client -> client2.9.5 drwxrwxr-x 11 dotpc dotpc 4096 Sep 2 2005 client-2.8.9 drwxrwxr-x 7 dotpc dotpc 4096 Dec 14 12:13 data drwxr-xr-x 12 dotpc dotpc 4096 Oct 21 09:41 docs drwxr-xr-x 5 dotpc dotpc 4096 Dec 7 14:22 etc drwxr-xr-x 11 dotpc dotpc 4096 Mar 21 15:54 client-2.9.5 -rw-r--r-- 1 dotpc dotpc 644836 Mar 22 09:53 client2.9.5.tar.gz 98. 99. 10 0. 10 1. 10 If you would like to run two commands in sequence what operators you can use? How you will uncompress the file? How do you execute a program or script, my_script in your current directory? How to find current time configuration in the file my_new.cfg? What does grep() stand for?

2. 10 3 10 4 10 5 10 6 What does the top command display? How can you find configuration on linux? How to find difference in two configuration files on the same server? What is the best way to see the end of a logfile.log file?

1. 2. 3. 4. 5. 6. 7.

What are the main differences between Apache 1.x and 2.x? What does the route command do? What are the read/write/execute bits on a directory mean? What does iostat do? what does vmstat do? What does netstat do? What is the most graceful way to bring a system into single user mode?

Ans 7: kill -TERM 1 8. How do you determine disk usage? Ans 8: The disk usage can be determined by using the command , du. This command outputs the number of kilobytes used by each sub-directory. 9. What is AWK? Ans 9:AWK is a complete pattern scanning and processing language, it is most commonly used as a Unix command-line filter to reformat the output of other commands. For example, to print only the second and sixth fields of the date command (the month and year) with a space separating them, at the Unix prompt, you would enter: date | awk {print $2 $6} 10.What is SED? SED (which stands for Stream EDitor) is a simple but powerful computer program used to apply various pre-specified textual

transformations to a sequential stream of text data. It reads input files line by line, edits each line according to rules specified in its simple language (the sed script), and then outputs the line. 11.What is the difference between binaries in /bin, and /usr/bin? /bin - would contains the binaries frequently used by the normal user (as well as system administrator) /usr/bin - would contains the binaries rarely used by the normal user (as wel as system administrator) 1. Under Solaris, there is no difference. /bin is a symbolic link pointing to /usr/bin. Under Linux (RHAS3) /bin is seemingly for standard unix programs like vi, cp, mv, rm which youd need in a single user environment where as /usr/bin contains programs youd want for a multiuser environment. Keep in mind that sometimes /usr is a different disk partition and when you start up in single user mode you only have / mounted. The /sbin directories are *supposed to* contain statically linked programs. This mas morphed into the idea of bin for user programs, sbin for admin programs.

12. What is a dynamically linked file? soft link (created with ln -s). Source and destination files will have the different inode. If dest removed source will be available. If source removed dest also will available but no where to go. This is confusing because of the use of the word file. A dynamically linked program is one that, when executed, loads shared libraries from /lib or /usr/lib in order to execute. The idea is that most programs use many of the same functions, so include a copy of a common function in *every* program on the file system. Instead, the function is placed in a shared library and when the program starts executing, the library is loaded which provides the program access to the function. 13. What is a statically linked file? hard link (created with ln). Source and dest will have the same inode. Making two different copies causes more disk space due to redundancy.

As above, confusing due to the use of the word file. A statically linked program is one that contains all the information (libraries) it needs to run. It does not need to load additional libaries in order to execute. Mutex: Short for mutual exclusion object. In computer programming, a mutex is a program object that allows multiple program threads to share the same resource, such as file access, but not simultaneously. When a program is started, a mutex is created with a unique name. After this stage, any thread that needs the resource must lock the mutex from other threads while it is using the resource. The mutex is set to unlock when the data is no longer needed or the routine is finished. INode: a unique number associated with each filename. This number is used to look up an entry in the inode table which gives information on the type, size, and location of the file and the userid of the owner of the file.

how do you configure linux system as a router? Enable packet forwarding For that we should echo "1" > /proc/sys/net/ipv4/ip_forward apply the above command Make it permanent by adding "net.ipv4.ip_forward = 1" to /etc/sysctl.conf or # /etc/sysctl.conf enable ip packet forwarding net.ipv4.ip_forward = 1 In IIS Version 6.0 Through application pool we can provide different -2 applications for the client. Is it right? If yes then how to provide the application to the client and what kind of application it can be ? If you are running your IIS server with 2 different versions of framework(1.1 & 2.0)you can create 2 different application pools and point your application to the required framework you want to run.

yes it is correct The problem might be a application pool will be associated with 2 different application that uses different frameworks.

What is Linux and why is it so popular? Answer Linux is an operating system that uses UNIX like Operating system. However, unlike UNIX, Linux is an open source and free software. Linux was originally created by Linus Torvalds and commonly used in servers. Popularity of Linux is because of the following reasons

It is free and open source. We can download Linux for free and customize it as per our needs. It is very robust and adaptable. Immense amount of libraries and utilities

What is Linux and why is it so popular? Linux is a multiuser, multitask GUI based open source operating system developed by Linus Torvalds Torvalds has invited the community to enhance the Linux kernel and thousands of system programmers worked on to enhance. Prior to Linux, there is UNIX. The desktop work stations from various companies were based on UNIX. Later a numerous companies entered and each one of them had their own UNIX version. As the proprietary authority is owned by each company and the lack of central authority weaken UNIX. As Linux is free and runs on any PC platform it gained the popularity very quickly. The following are few more reasons for its popularity: - People who are familiar with UNIX can work on Linux with ease and comfort. - People who want great control over network security and on operating system

What is LILO? Answer LILO is Linux Loader is a boot loader for Linux. It is used to load Linux into the memory and start the Operating system. LILO can be configured to boot other operating systems as well. LILO is customizable, which means that if the default configuration is not correct, it can be changed. Config file for LILO is lilo.conf.

What is LILO? LILO stands for Linux Loader which is a bootstrap program. LILO is a code snippet which loads PC BIOS into the main memory at the time of starting the computer system. LILO handles the following tasks: -Locating Linux kernel -Identifying other supporting programs and loading them in the memory -Staring Kernel The selection of various kernel images and boot routines is supported by LILO. For this reason, LILO is known as boot manager. What is the difference between home directory and working directory? Answer Home directory is the default working directory when a user logs in. On the other hand, working directory is the users current directory. Working directory can be changed. It can be changed using cd command. Home directory in Linux contains users personal data, configuration files, settings of a software etc. The content of home directory is private and the user has a complete control of it. What is the difference between home directory and working directory? Home Directory: Every user will have one home directory and will have complete control over it. On login, home is the default working directory for the user. It contains the configuration files and responsible for login and logout of the user. Working directory: The directory in which the user is working currently is known as working directory. The home may also be the working directory, if the user is working in it.

What is the difference between internal and external commands? Answer Internal commands are commands that are already loaded in the system. They can be executed any time and are independent. On the other hand, external commands are loaded when the user requests for them. Internal commands dont require a separate process to execute them. External commands will have an individual process. Internal commands are a part of the shell while external commands require a Path. If the files for the command are not present in the path, the external command wont execute.

What is the difference between internal and external commands? The commands that are directly executed by the shell are known as internal commands. No separate process is there to run these commands. The commands that are executed by the kernel are knows as external commands. Each command has its unique process id. Explain the difference between a static library and a dynamic library? Answer Static libraries are loaded when the program is compiled and dynamicallylinked libraries are loaded in while the program is running. Dynamic libraries save the RAM space as against the static library because linking to static libraries includes the actual code for the library function(s)/procedure(s) with the executable. DLL code is kept at one location and is usually shared among all the processes that use the DLL. Explain the difference between a static library and a dynamic library. Static library has functionality that bound to a static program at compile time. Every static program has its own copy of library. Dynamic libraries are loaded into the memory and binds at run time. The external functionality is accessed at runtime. This process reduces the overall footprint of memory. What is LD_LIBRARY_PATH? Answer LD_LIBRARY_PATH is an environment variable. It is used for debugging a new library or a non standard library. It is also used for which directories to search. Path to search for directories needs to given. The variable can be set by using setenvLD_LIBRARY_PATH--$PATH Linux - What is LD_LIBRARY_PATH? - May 11, 2009 at 14:00 pm by Vidya Sagar What is LD_LIBRARY_PATH? LD_LIBRARY_PATH is an environment variable. This is used to search for the shared objects / dynamic libraries by the operating system for extendable functionality at runtime. What is the file server in Linux server? Answer File server is used for file sharing. It enables the processes required fro sharing. All the files can be stored at a centralized location. Linux uses Samba

to view the files on the server. Files on this server are backed up on a regular basis. Rights can be also assigned for the files on a file server. What is the file server in Linux server? A file server is dedicated for persisting files in a location from which the networked systems can access. Certain access privileges can be set for files. Linux has software named as samba which allows the files to be shared, viewed and edited on any remote system which may has Windows 9 x/ME/2000/NT or Macintosh computer systems. These files on the file server are backed up from time to time. If a file is deleted inadvertently, the file can be recovered from the backup tape. What is NFS? What is its purpose? Answer NFS is Network File system. It is a file system used for sharing of files over a network. Other resources like printers and storage devices can also be shared. This means that using NFS files can be accessed remotely. Nfs command in linux can be used to achieve this. Purpose of NFS:

NFS can be used for sharing of files remotely. Data can be stored on a single machine and still remain accessible to others over the network. Reduction of the number of removable media drives throughout the network since they can be shared.

What is NFS? What is its purpose? NFS stands for Network File System. NFS is used to partition a disk on a remote machine disk. NFS allows a quick way of file sharing. The unwanted people access potential is provided by NFS to access hard drive in a network. So that an unauthorized user can not access ones email, delete the files. File services from windows can be accessed. In other words files from one operating system can be shared by another using NFS. How do I send email with linux? Answer Email can be sent in Linux using the mail command. Mail [options] [users] Options include: -s for subject, -c for carbon copy, -b for blind carbon copy E.g. mail user_name s hello

How do I send email with Linux? Linux supports to work with sending mails using a set of commands called as mail commands. The command to send email is mail. The mail command is used to send and receive emails. Syntax: mail [options] [users] Options are: -s,-c,-b Where s for subject, -c for copy and b for blind carbon copy Ex: mail username s Reports are needed It prompts displays the subject as Reports are needed. Similarly if c and b is given the mail will be sent to the corresponding recipients. Explain RPM (Red Hat Package Manager) features. Answer RPM is a package managing system (collection of tools to manage software packages). Features:

RPM can verify software packages. RPM can be served as a powerful search engine to search for softwares. Components, softwares etc can be upgraded using RPM without having to reinstall them Installing, reinstalling can be done with ease using RPM During updates RPM handles configuration files carefully, so that the customization is not lost.

Explain RPM (Red Hat Package Manager) features. RPM is a powerful software management tool for installing, uninstalling, verifying, querying and updating software packages. RPM is a straight forward program to perform the above software management tasks. It is available with Fedora, Suse, CentOS, Mandriva Linux and other version of Linux. What is Kernel? Explain the task it performs. Answer Kernel is used in UNIX like systems and is considered to be the heart of the operating system. It is responsible for communication between hardware and software components. It is primarily used for managing the systems resources as well.

Kernel Activities:

The Kernel task manager allows tasks to run concurrently. Managing the computer resources: Kernel allows the other programs to run and use the resources. Resources include i/o devices, CPU, memory. Kernel is responsible for Process management. It allows multiple processes to run simultaneously allowing user to multitask. Kernel has an access to the systems memory and allows the processes to access the memory when required. Processes may also need to access the devices attached to the system. Kernel assists the processes in doing so. For the processes to access and make use of these services, system calls are used.

What is Kernel? Explain the task it performs. Kernel is the component that is responsible for managing the resources of a computer system. The tasks are: - Provides the abstraction level for resources such as memory, processors, and I/O devices. -Performs inter process communication -Responds to system calls -Provides methods for synchronization and communication between processes. What is Linux Shell? What is Shell Script? Answer Linux shell is a user interface used for executing the commands. Shell is a program the user uses for executing the commands. In UNIX, any program can be the users shell. Shell categories in Linux are: Bourne shell compatible, C shell compatible, nontraditional, and historical. A shell script, as the name suggests, is a script written for the shell. Script here means a programming language used to control the application. The shell script allows different commands entered in the shell to be executed. Shell script is easy to debug, quicker as compared to writing big programs. However the execution speed is slow because it launches a new process for every shell command executed. Examples of commands are cp, cn, cd. What is Linux Shell? What is Shell Script? Linux shell is the user interface to communicate with Linux operating system. Shell interprets the user requests, executes them. Shell may use kernel to

execute certain programs. Shell Script: A shell script is a program file in which certain Linux commands are placed to execute one after another. A shell script is a flat text file. Shell scripts are useful to accept inputs and provide output to the user. Everyday automation process can be simplified by a shell script. What are Pipes? Explain use of pipes. Answer A pipe is a chain of processes so that output of one process (stdout) is fed an input (stdin) to another. UNIX shell has a special syntax for creation of pipelines. The commands are written in sequence separated by |. Different filters are used for Pipes like AWK, GREP. e.g. sort file | lpr ( sort the file and send it to printer) Uses of Pipe

Several powerful functions can be in a single statement Streams of processes can be redirected to user specified locations using >

What are Pipes? Explain use of pipes. Pipe is a symbol used to provide output of one command as input to another command. The output of the command to the left of the pipe is sent as input to the command to the right of the pipe. The symbol is |. For example: $ cat apple.txt | wc In the above example the output of apple.txt file will be sent as input for wc command which counts the no. of words in a file. The file for which the no. of words counts is the file apple.txt. Pipes are useful to chain up several programs, so that multiple commands can execute at once without using a shell script. Explain trap command, shift Command, getopts command of linux. Answer Trap command: controls the action to be taken by the shell when a signal is received. Trap [OPTIONS] [ [arg] signspec..] Arg is the action to be taken or executed on receiving a signal specified in signspec. e.g. trap rm $FILE; exit // exit (signal) and remove file (action)

Shift Command: Using shift command, command line arguments can be accessed. The command causes the positional parameters shift to the left. Shift [n] where n defaults to 1. It is useful when several parameters need to be tested. Getopts command: this command is used to parse arguments passed. It examines the next command line argument and determines whether it is a valid option Getopts {optstring} {variable1}. Here, optsring contains letters to be recognized if a letter is followed by a colon, an argument should be specified. E.g (whether the argument begins with a minus sign and is followed by any single letter contained inside options ) If not, diagnostic messages are shown. It is usually executed inside a loop. Explain trap command; shift Command, getopts command of linux. trap command is used to catch a signal that is sent to a process. An action is taken based on the signal by using the action which is defined in the trap command instead of taking the default effect on the process. Example: $ trap echo interrupt signal received INT. shift command is used to replace the parameters that were sent from command line. For example $ shift will replace $1 by $2 getopts command is used for the purpose of parsing positional parameters. What Stateless Linux server? What feature it offers? Answer A stateless Linux server is a centralized server in which no state exists on the single workstations. There may be scenarios when a state of a partilcuar system is meaningful (A snap shot is taken then) and the user wants all the other machines to be in that state. This is where the stateless Linux server comes into picture. Features:

It stores the prototypes of every machine It stores snapshots taken for those systems It stores home directories for those systems Uses LDAP containing information of all systems to assist in finding out which snapshot (of state) should be running on which system.

What Stateless Linux server? What feature it offers? Stateless linux is a way how a system is to run and be managed. Being a stateless system, a system should be able to be replaced at any time with or without local storage media. In case of hard drive crash, the command resync can be used to a new drive. If server goes offline, a new virtual instance that is running the OS image off of the network storage. What does nslookup do? Explain its two modes. Answer Nslookup is used to find details related to a Domain name server. Details like IP addresses of a machine, MX records, servers etc. It sends a domain name query packet to the corresponding DNS. Nslookup has two modes. Interactive and non interactive. Interactive mode allows the user to interact by querying information about different hosts and domains. Non interactive mode is used to fetch information about the specified host or domain. Interactive mode: Nslookup [options] [server] What does nslookup do? Explain its two modes. Nslookup is a program used to find information about internet Domain Name server. The two modes of nslookup are: Interactive and non-interactive. Using interactive mode user can query the name servers for the information pertaining to hosts and domains. Using non-interactive mode the user can just print the name and requested information of a host. What is Bash Shell? Answer Bash is a free shell for UNIX. It is the default shell for most UNIX systems. It has a combination of the C and Korn shell features. Bash shell is not portable. any Bash-specific feature will not function on a system using the Bourne shell or one of its replacements, unless bash is installed as a secondary shell and the script begins with #!/bin/bash. It supports regular and expressions. When bash script starts, it executes commands of different scripts.

What is Bash Shell? Bash stands for "Bourne Again Shell. A shell is the user interface. Bash is more convenient shell for users among others. The scripts written in Bash are portable among machines, distributions and even operating systems. Explain some Network-Monitoring Tools in Linux: ping, traceroute, tcpdump, ntop Answer Network monitoring tools are used to monitor the network, systems present on the network, traffic etc. Ping: Ping command is used to check if the system is in the network or not. To check if the host is operating. e.g. ping ip_address When the command is executed, it returns a detailed summary of the host. Packets sent, received, lost by estimating the round trip time. Traceroute: the command is used to trace the path taken by the packet across a network. Tracing the path here means finding out the hosts visited by the packet to reach its destination. This information is useful in debugging. Roundtrip time in ms is shown for every visit to a host. Tcpdump: commonly used to monitor network traffic. Tcdump captures and displays packet headers and matching them against criteria or all. It interprets Boolean operators and accepts host names, ip address, network names as arguments. Ntop: Network top shows the network usage. It displays summary of network usage by machines on the network in a format as of UNIX top utility. It can also be run in web mode, which allows the display to be browsed with a web browser. It can display network traffic statistics, identify host etc. Interfaces are available to view such information. Explain some Network-Monitoring Tools in Linux: ping, traceroute, tcpdump, ntop ping: Used to check whether the system is in the network or not and sends Internet Control Message Protocol ECHO_REQUEST packets to the hosts of network. traceroute: Prints the route packets which were taken by the network host. traceroute utilizes the internet protocols time to live field and elicits an ICMP TIME_EXCEEDED response. This response is elicited from every gateway including the path to one of the hosts.

tcpdump: To dump traffic over a network tcpdump command is used. The headers of the packets over a network interface are printed if the given Boolean expression is true. ntop: Network top program. It displays the summary of network usage of systems over network in a format which is reminiscent of unix top utility. If used in web mode, it displays the result on the web browser. How does the linux file system work? Answer Linux file structure is a tree like structure. It starts from the root directory, represented by '/', and then expands into sub-directories. All the partitions are under the root directory. If a partition is mounted (The mount point defines the place of a particular data set in the file system) anywhere apart from a device, the system is not aware of the existence of that partition or device. Directories that are only one level below the root directory are often preceded by a slash, to indicate their position. Explain file system of linux. The root "/" filesystem, /usr filesystem, /var filesystem, /home filesystem, /proc filesystem. Answer Root "/" file system: The kernel needs a root file system to mount at start up. The root file system is generally small and should not be changed often as it may interrupt in booting. The root directory usually does not have the critical files. Instead sub directories are created. E.g. /bin (commands needed during bootup), /etc (config files) , /lib(shared libraries). /usr filesystem : this file system is generally large as it contains the executable files to be shared amongst different machines. Files are usually the ones installed while installing Linux. This makes it possible to update the system from a new version of the distribution, or even a completely new distribution, without having to install all programs again. Sub directories include /bin, /include, /lib, /local (for local executables) /var filesystem : this file system is specific to local systems. It is called as var because the data keeps changing. The sub directories include /cache/man (A cache for man pages), /games (any variable data belong to games), /lib (files that change), /log (log from different programs), /tmp (for temporary files) /home filesystem: - this file system differs from host to host. User specific configuration files for applications are stored in the user's home directory in a file. UNIX creates directories for all users directory. E.g /home/my_name. Once the user is logged in ; he is placed in his home directory. /proc filesystem : this file system does not exist on the hard disk. It is created by the kernel in its memory to provide information about the system.

This information is usually about the processes. Contains a hierarchy of special files which represent the current state of the kernel .Few of the Directories include /1 (directory with information about process num 1, where 1 is the identification number), /cpuinfo (information about cpu), /devices (information about devices installed), /filesystem (file systems configured), /net (information about network protocols), /mem (memory usage) How does the Linux file system work? At the time of installation of Linux, a file system is assigned and persists in the hard disk. This file system structure resembles a tree. A file can be a list of names and numbers or executable programs. Linux treats every program as a file. Linux treats directories and computer components also as files. A file could be a list of names and numbers, a cheesecake recipe, or an executable program. But under Linux, everything is a file. In addition to data and executable files, Linux treats directories and even the various components of your computer as files. It could be a keyboard, console, and printer, RAM or ROM. These are referred as special files known as devices. These files are available in /dev directory. Linux performs the communication with these devices by simply reading from or writing to these special files. What are the process states in Linux? Answer Process states in Linux:

Running: Process is either running or ready to run Interruptible: a Blocked state of a process and waiting for an event or signal from another process Uninterruptible: a blocked state. Process waits for a hardware condition and cannot handle any signal Stopped: Process is stopped or halted and can be restarted by some other process Zombie: process terminated, but information is still there in the process table.

Linux - What are the process states in Linux? - August 21, 2008 at 22:00 pm by Rajmeet Ghai What are the process states in Linux? The following are the process states: 1. Running: This is a state where a process is either in running or ready to run. 2. Interruptible: This state is a blocked state of a process which awaits for an event or a signal from another process 3. Uninterruptible: It is also a blocked state. The process is forced to halt

for certain condition that a hardware status is waited and a signal could not be handled. 4. Stopped: Once the process is completed, this state occurs. This process can be restarted 5. Zombie: In this state, the process will be terminated and the information will still be available in the process table. What is a zombie? Answer Zombie is a process state when the child dies before the parent process. In this case the structural information of the process is still in the process table. Since this process is not alive, it cannot react to signals. Zombie state can finish when the parent dies. All resources of the zombie state process are cleared by the kernel What is a zombie? Dead process is called a zombie. The processes will die eventually at the time when they become zombies. A dead process cannot be killed. The parent process will send a signal to the operating system that is not needed the zombie by using wait () system call. Explain each system calls used for process management in linux. Answer System calls used for Process management:

Fork () :- Used to create a new process Exec() :- Execute a new program Wait():- wait until the process finishes execution Exit():- Exit from the process Getpid():- get the unique process id of the process Getppid():- get the parent process unique id Nice():- to bias the existing property of process

Explain each system calls used for process management in linux. Process management uses certain system calls. They are explained below. 1. 2. 3. 4. 5. 6. 7. To To To To To To To create a new process fork () is used. run a new program = exec () is used. make the process to wait = wait () is used. terminate the process exit () is used. find the unique process id getpid () is used. find the parent process id getppid () is used. bias the currently running process property nice () is used.

Which file defines all users on your system? Choose one: a. /etc/passwd b. /etc/users c. /etc/password d. /etc/user.conf Answer: a The /etc/passwd file contains all the information on users who may log into your system. If a user account is not contained in this file, then the user cannot log in. Which two commands can you use to delete directories? A) rm B) rm -rf C) rmdir D) rd E) rd -rf Answer(s): B, C - You can use rmdir or rm -rf to delete a directory. Answer a is incorrect, because the rm command without any specific flags will not delete a directory, it will only delete files. Answers d and e point to a non-existent command. Which partitioning tool is available in all distributions? A) Disk Druid B) fdisk C) Partition Magic D) FAT32 E) System Commander Answer(s): B - The fdisk partitioning tool is available in all Linux distributions. Answers a, c, and e all handle partitioning, but do not come with all distributions. Disk Druid is made by Red Hat and used in its distribution along with some derivatives. Partition Magic and System Commander are tools made by third-party companies. Answer d is not a tool, but a file system type. Specifically, FAT32 is the file system type used in Windows 98. Which partitions might you create on the mail server's hard drive(s) other than the root, swap, and boot partitions? [Choose all correct answers] A) /var/spool B) /tmp C) /proc D) /bin E) /home Answer(s): A, B, E - Separating /var/spool onto its own partition helps to ensure that if something goes wrong with the mail server or spool, the output cannot overrun the file system. Putting /tmp on its own partition prevents either software or user items in the /tmp directory from overrunning the file system. Placing /home off on its own is mostly useful for system re-installs or upgrades, allowing you to not have to wipe the /home hierarchy along with

other areas. Answers c and d are not possible, as the /proc portion of the file system is virtual-held in RAM-not placed on the hard drives, and the /bin hierarchy is necessary for basic system functionality and, therefore, not one that you can place on a different partition. When planning your backup strategy you need to consider how often you will perform a backup, how much time the backup takes and what media you will use. What other factor must you consider when planning your backup strategy?_________ what to backup Choosing which files to backup is the first step in planning your backup strategy. What utility can you use to automate rotation of logs? Answer: logrotate The logrotate command can be used to automate the rotation of various logs. In order to display the last five commands you have entered using the history command, you would type ___________ . Answer: history 5 The history command displays the commands you have previously entered. By passing it an argument of 5, only the last five commands will be displayed. What command can you use to review boot messages? Answer: dmesg The dmesg command displays the system messages contained in the kernel ring buffer. By using this command immediately after booting your computer, you will see the boot messages. What is the minimum number of partitions you need to install Linux? Answer: 2 Linux can be installed on two partitions, one as / which will contain all files and a swap partition. What is the name and path of the main system log? Answer: /var/log/messages By default, the main system log is /var/log/messages. Of the following technologies, which is considered a client-side script? A) JavaScript B) Java C) ASP D) C++ Answer: A - JavaScript is the only client-side script listed. Java and C++ are complete programming languages. Active Server Pages are parsed on the server with the results being sent to the client in HTML

Linux Interview Questions And Answers Set - 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. Who owns the data dictionary? The SYS user owns the data dictionary. The SYS and SYSTEM users are created when the database is created. 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. 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. 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.

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. 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. 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. Where is standard output usually directed? to the screen or display

By default, your shell directs standard output to your screen or display. 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.

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. 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. 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. 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. 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. 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. 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. In order to run fsck on the root partition, the root partition must be mounted as readonly

You cannot run fsck on a partition that is mounted as read-write. In order to improve your system's security you decide to implement shadow passwords. What command should you use? pwconv

The pwconv command creates the file /etc/shadow and changes all passwords to 'x' in the /etc/passwd file. Bob Armstrong, who has a username of boba, calls to tell you he forgot his password. What command should you use to reset his command? passwd boba

The passwd command is used to change your password. If you do not specify a username, your password will be changed. The top utility can be used to change the priority of a running process? Another utility that can also be used to change priority is ___________? nice

Both the top and nice utilities provide the capability to change the priority of a running process. What command should you type to see all the files with an extension of 'mem' listed in reverse alphabetical order in the /home/ben/memos directory. ls -r /home/ben/memos/*.mem

The -c option used with ls results in the files being listed in chronological order. You can use wildcards with the ls command to specify a pattern of filenames.

What file defines the levels of messages written to system log files? kernel.h

To determine the various levels of messages that are defined on your system, examine the kernel.h file. What command is used to remove the password assigned to a group? gpasswd -r

The gpasswd command is used to change the password assigned to a group. Use the -r option to remove the password from the group.

What command would you type to use the cpio to create a backup called backup.cpio of all the users' home directories? find /home | cpio -o > backup.cpio

The find command is used to create a list of the files and directories contained in home. This list is then piped to the cpio utility as a list of files to include and the output is saved to a file called backup.cpio. What can you type at a command line to determine which shell you are using? echo $SHELL

The name and path to the shell you are using is saved to the SHELL environment variable. You can then use the echo command to print out the value of any variable by preceding the variable's name with $. Therefore, typing echo $SHELL will display the name of your shell. What type of local file server can you use to provide the distribution installation materials to the new machine during a network installation? A) Inetd B) FSSTND C) DNS D) NNTP E) NFS E - You can use an NFS server to provide the distribution installation materials to the machine on which you are performing the installation. Answers a, b, c, and d are all valid items but none of them are file servers. Inetd is the superdaemon which controls all intermittently used network services. The FSSTND is the Linux File System Standard. DNS provides domain name resolution, and NNTP is the transfer protocol for usenet news.

If you type the command cat dog & > cat what would you see on your display? Choose one: a. Any error messages only. b. The contents of the file dog. c. The contents of the file dog and any error messages. d. Nothing as all output is saved to the file cat.

Answer : d

When you use & > for redirection, it redirects both the standard output and standard error. The output would be saved to the file cat. You are covering for another system administrator and one of the users asks you to restore a file for him. You locate the correct tarfile by checking the backup log but do not know how the directory structure was stored. What command can you use to determine this? Choose one: a. tar fx tarfile dirname b. tar tvf tarfile filename c. tar ctf tarfile d. tar tvf tarfile

Answer : d

The t switch will list the files contained in the tarfile. Using the v modifier will display the stored directory structure. You have the /var directory on its own partition. You have run out of space. What should you do? Choose one: a. Reconfigure your system to not write to the log files. b. Use fips to enlarge the partition. c. Delete all the log files.

d. Delete the partition and recreate it with a larger size. Answer :d The only way to enlarge a partition is to delete it and recreate it. You will then have to restore the necessary files from backup. You have a new application on a CD-ROM that you wish to install. What should your first step be? Choose one: a. Read the installation instructions on the CD-ROM. b. Use the mount command to mount your CD-ROM as read-write. c. Use the umount command to access your CD-ROM. d. Use the mount command to mount your CD-ROM as read-only.

Answer : d

Before you can read any of the files contained on the CD-ROM, you must first mount the CD-ROM. When you create a new partition, you need to designate its size by defining the starting and ending _____________. cylinders

When creating a new partition you must first specify its starting cylinder. You can then either specify its size or the ending cylinder.

What key combination can you press to suspend a running job and place it in the background? ctrl-z

Using ctrl-z will suspend a job and put it in the background.

The easiest, most basic form of backing up a file is to _____ it to another location. copy

The easiest most basic form of backing up a file is to make a copy of that file to another location such as a floppy disk. What type of server is used to remotely assign IP addresses to machines during the installation process? A) SMB B) NFS C) DHCP D) FT E) HTTP

C - You can use a DHCP server to assign IP addresses to individual machines during the installation process. Answers a, b, d, and e list legitimate Linux servers, but these servers do not provide IP addresses. The SMB, or Samba, tool is used for file and print sharing across multi-OS networks. An NFS server is for file sharing across Linux net-works. FTP is a file storage server that allows people to browse and retrieve information by logging in to it, and HTTP is for the Web. Which password package should you install to ensure that the central password file couldn't be stolen easily? A) PAM B) tcp_wrappers C) shadow D) securepass E) ssh

C - The shadow password package moves the central password file to a more

secure location. Answers a, b, and e all point to valid packages, but none of these places the password file in a more secure location. Answer d points to an invalid package. When using useradd to create a new user account, which of the following tasks is not done automatically. Choose one: a. Assign a UID. b. Assign a default shell. c. Create the user's home directory. d. Define the user's home directory. Answer c The useradd command will use the system default for the user's home directory. The home directory is not created, however, unless you use the -m option. You want to enter a series of commands from the command-line. What would be the quickest way to do this? Choose One a. Press enter after entering each command and its arguments b. Put them in a script and execute the script c. Separate each command with a semi-colon (;) and press enter after the last command d. Separate each command with a / and press enter after the last command Answer c

The semi-colon may be used to tell the shell that you are entering multiple commands that should be executed serially. If these were commands that you would frequently want to run, then a script might be more efficient. However, to run these commands only once, enter the commands directly at the command line.

You attempt to use shadow passwords but are unsuccessful. What characteristic of the /etc/passwd file may cause this? Choose one: a. The login command is missing. b. The username is too long. c. The password field is blank. d. The password field is prefaced by an asterisk. Answer :c The password field must not be blank before converting to shadow passwords. When you install a new application, documentation on that application is also usually installed. Where would you look for the documentation after installing an application called MyApp? Choose one: a. /usr/MyApp b. /lib/doc/MyApp c. /usr/doc/MyApp d. In the same directory where the application is installed. Answer : c The default location for application documentation is in a directory named for the application in the /usr/doc directory. What file would you edit in your home directory to change which window manager you want to use? A) Xinit B) .xinitrc C) XF86Setup D) xstart E) xf86init

Answer: B - The ~/.xinitrc file allows you to set which window man-ager you

want to use when logging in to X from that account. Answers a, d, and e are all invalid files. Answer c is the main X server configuration file. What command allows you to set a processor-intensive job to use less CPU time? A) ps B) nice C) chps D) less E) more

Answer: B - The nice command is used to change a job's priority level, so that it runs slower or faster. Answers a, d, and e are valid commands but are not used to change process information. Answer c is an invalid command. While logged on as a regular user, your boss calls up and wants you to create a new user account immediately. How can you do this without first having to close your work, log off and logon as root? Choose one: a. Issue the command rootlog. b. Issue the command su and type exit when finished. c. Issue the command su and type logoff when finished. d. Issue the command logon root and type exit when finished.

Answer: b You can use the su command to imitate any user including root. You will be prompted for the password for the root account. Once you have provided it you are logged in as root and can do any administrative duties.

There are seven fields in the /etc/passwd file. Which of the following lists all the fields in the correct order? Choose one: a. username, UID, GID, home directory, command, comment b. username, UID, GID, comment, home directory, command c. UID, username, GID, home directory, comment, command d. username, UID, group name, GID, home directory, comment Answer: b The seven fields required for each line in the /etc/passwd file are username, UID, GID, comment, home directory, command. Each of these fields must be separated by a colon even if they are empty. Which of the following commands will show a list of the files in your home directory including hidden files and the contents of all subdirectories? Choose one: a. ls -c home b. ls -aR /home/username c. ls -aF /home/username d. ls -l /home/username

Answer: b The ls command is used to display a listing of files. The -a option will cause hidden files to be displayed as well. The -R option causes ls to recurse down the directory tree. All of this starts at your home directory. In order to prevent a user from logging in, you can add a(n) ________at the beginning of the password field. Answer: asterick

If you add an asterick at the beginning of the password field in the /etc/passwd file, that user will not be able to log in.

You have a directory called /home/ben/memos and want to move it to /home/bob/memos so you issue the command mv /home/ben/memos /home/bob. What is the results of this action? Choose one: a. The files contained in /home/ben/memos are moved to the directory /home/bob/memos/memos. b. The files contained in /home/ben/memos are moved to the directory /home/bob/memos. c. The files contained in /home/ben/memos are moved to the directory /home/bob/. d. The command fails since a directory called memos already exists in the target directory.

Answer: a When using the mv command to move a directory, if a directory of the same name exists then a subdirectory is created for the files to be moved. Which of the following tasks is not necessary when creating a new user by editing the /etc/passwd file? Choose one: a. Create a link from the user's home directory to the shell the user will use. b. Create the user's home directory c. Use the passwd command to assign a password to the account. d. Add the user to the specified group.

Answer: a There is no need to link the user's home directory to the shell command. Rather, the specified shell must be present on your system. You issue the following command useradd -m bobm But the user cannot logon. What is the problem?

Choose one: a. You need to assign a password to bobm's account using the passwd command. b. You need to create bobm's home directory and set the appropriate permissions. c. You need to edit the /etc/passwd file and assign a shell for bobm's account. d. The username must be at least five characters long.

Answer: a The useradd command does not assign a password to newly created accounts. You will still need to use the passwd command to assign a password. You wish to print the file vacations with 60 lines to a page. Which of the following commands will accomplish this? Choose one: a. pr -l60 vacations | lpr b. pr -f vacations | lpr c. pr -m vacations | lpr d. pr -l vacations | lpr

Answer: a The default page length when using pr is 66 lines. The -l option is used to specify a different length. Linux Interview Questions And Answers Set - 5

Which file defines all users on your system? Choose one: a. /etc/passwd

b. /etc/users c. /etc/password d. /etc/user.conf

Answer: a The /etc/passwd file contains all the information on users who may log into your system. If a user account is not contained in this file, then the user cannot log in. Which two commands can you use to delete directories? A) rm B) rm -rf C) rmdir D) rd E) rd -rf

Answer(s): B, C - You can use rmdir or rm -rf to delete a directory. Answer a is incorrect, because the rm command without any specific flags will not delete a directory, it will only delete files. Answers d and e point to a non-existent command. Which partitioning tool is available in all distributions? A) Disk Druid B) fdisk C) Partition Magic D) FAT32 E) System Commander

Answer(s): B - The fdisk partitioning tool is available in all Linux distributions. Answers a, c, and e all handle partitioning, but do not come with all distributions. Disk Druid is made by Red Hat and used in its distribution along with some derivatives. Partition Magic and System Commander are tools

made by third-party companies. Answer d is not a tool, but a file system type. Specifically, FAT32 is the file system type used in Windows 98. Which partitions might you create on the mail server's hard drive(s) other than the root, swap, and boot partitions? [Choose all correct answers] A) /var/spool B) /tmp C) /proc D) /bin E) /home

Answer(s): A, B, E - Separating /var/spool onto its own partition helps to ensure that if something goes wrong with the mail server or spool, the output cannot overrun the file system. Putting /tmp on its own partition prevents either software or user items in the /tmp directory from overrunning the file system. Placing /home off on its own is mostly useful for system re-installs or upgrades, allowing you to not have to wipe the /home hierarchy along with other areas. Answers c and d are not possible, as the /proc portion of the file system is virtual-held in RAM-not placed on the hard drives, and the /bin hierarchy is necessary for basic system functionality and, therefore, not one that you can place on a different partition. When planning your backup strategy you need to consider how often you will perform a backup, how much time the backup takes and what media you will use. What other factor must you consider when planning your backup strategy?_________

what to backup Choosing which files to backup is the first step in planning your backup strategy.

What utility can you use to automate rotation of logs? Answer: logrotate The logrotate command can be used to automate the rotation of various logs. In order to display the last five commands you have entered using the history command, you would type ___________ .

Answer: history 5 The history command displays the commands you have previously entered. By passing it an argument of 5, only the last five commands will be displayed. What command can you use to review boot messages? Answer: dmesg The dmesg command displays the system messages contained in the kernel ring buffer. By using this command immediately after booting your computer, you will see the boot messages. What is the minimum number of partitions you need to install Linux? Answer: 2 Linux can be installed on two partitions, one as / which will contain all files and a swap partition. What is the name and path of the main system log? Answer: /var/log/messages By default, the main system log is /var/log/messages. Of the following technologies, which is considered a client-side script? A) JavaScript B) Java C) ASP D) C++

Answer: A - JavaScript is the only client-side script listed. Java and C++ are

complete programming languages. Active Server Pages are parsed on the server with the results being sent to the client in HTML
what is the UID and GID of root user? Can a normal user can change the ownership of a file? what is the command to change ownership of a file? the root UID/GID is 0 (zero). which is why he can able to intervene in all normal users files even though he don't had permission. A normal user will don't have the permission to change ownership of file. The command to change ownership is < chown user.user file >

What is Sticky bit?


The "Sticky bit" in a unix or linux filesystem was originally designed to tell the OS to keep the program in cache, even after it loaded, so it would "stick" in memory. Although it made it faster to load the program the next time, it also made it difficult to do maintenance on the program, and it wasted memory if the program fell out of common use. For speedy program accesss, modern filesystem caches do a very good job, so the sticky bit is not often used for this any more. Instead, the sticky bit, when applied to a directory, means: if a user writes a file to this directory, only let that user change that file. It is very common for the /tmp directory to have the sticky bit set. /tmp is a shared resource that every user can write to, so the sticky bit makes sure that users cannot interfere with each other's temp files.

Is there a way to restrict the number of processes that any one user is allowed to run while using their shell?

There are two slightly different ways of doing this depending on whether your system uses PAM (Pluggable Authentication Modules). Ubuntu uses PAM by default, so you set limits in /etc/security/limits.conf. To limit user Fred to ten processes, add a line like this:
fred hard nproc 10

For systems not using PAM, the limits are set in /etc/limits, and the same restriction needs:
fred U10

In either case, you can use * as a username, to limit everyone but the root user. The limits set in these files are per login (rather than an overall limit for each user), but remember that a login for a graphical desktop may require several processes. A terminal window opened from this desktop is not, by default, a separate login, so set the limit to something reasonable to avoid crippling the desktop. To get an idea of the number of processes that a user runs with a standard startup, run
sudo ps -u fred | wc -l

I have an ubuntu server and I am using it for cpu heavy verifications. I want to limit the number of simultaneous verifications to 10. Is there an easy way to limit the process called "vis" to being able run only 10 of them at the same time? ulimit is the command to make these types of restrictions. I would recommend you make a user called visuser and add the following line to the .bashrc file: ulimit -u 10

Note that I use local$ to denote a shell prompt on a local machine and remote$ to do the same for the remote machine.
1. 2. 3. 4.
local$ ssh-keygen -t dsa local$ scp ~/.ssh/id_dsa.pub remote local$ ssh username@remote remote$ cat ~/id_dsa.pub >> ~/.ssh/authorized_keys

5.

- this was one of the things that kept throwing me, ssh doesn't like this file to be world of group writable.
remote$ chmod 644 ~/.ssh/authorized_keys remote$ exit

6. 7.

- Now instead of the normal password you should be asked for the password you entered for your dsa key. This isn't passwordless yet but shows that ssh is using the key. At this point you can either use ssh-agent or keychain to manage your keys so you don't need to type in passwords. Normally I would recommend keychain but I have been having problems with it recently so I will outline how to use ssh-agent.
local$ ssh username@remote local$ ssh-agent bash local$ ssh-add ~/.ssh/id_dsa

1. 2. 3.

- you will be prompted for your - your shouldn't be asked for the

key's passphrase.
local$ ssh username@remote

passphrase again. While you stay in the shell above you will never be prompted for a password for any ssh command. However this doesn't allow for things like cron jobs easily. An alternative way to use ssh agent would be to run it and source the settings it generates in your ~/.bashrc. 1. Edit ~/.bashrc and add the following at the end:
2. 3. 4. 5. 6. ssh_agent="$HOME/.ssh-agent.sh" if [ -f $ssh_agent ] then source $ssh_agent > /dev/null fi

Note that I pipe the output to /dev/null to stop the agent pid being echo'd which might make some commands fail (e.g. sftp).
7. 8. 9.
local$ ssh-agent > ~/.ssh-agent.sh

Either exit the shell and start a new one or


~/.ssh_agent.sh local$ ssh-add ~/.ssh/id_dsa

local$ source

10.

local$ ssh username@remote

- you shouldn't be prompted for a

password While ssh-agent is running all your processes (including your cron jobs) shouldn't need a password. However if ssh-agent dies or is killed things might go wrong since the old settings are left over. Keychain, which I mentioned above, tries to simplify and manage all this by automatically starting ssh-agent processes when needed. I have been having problems with it, for a start the web page is a little out of date, better using keychain --help as a guide. It essentially does what I outlined above though.

You might also like