You are on page 1of 36

ipsrfs@ipsrsolutions.

com

Sir/Madam, I am attaching my resume with this mail as per the job notification for your Company.Thank you for considering my application. I look forward to hearing from you.

Thanks and Regards, SREEHARI S AVITTATHUR VARIUM P O AVITTATHUR 9995555493


2india@m2comsys.com

Trainee System Administrato info@csnt.net Hardware- Netowrk Engineers hrd@accelfrontline.in Linux Administrator

LINUX ADMINISTRATOR

Our Differentiators

A company driven by ethics and strong values Transparent working environment, flat, non-hierarchical structure and open door policy that promotes free flow of ideas, opinions, information and expertise Provides a plethora of equal growth opportunities to all Mphasians Fair recognition for performance and hard work Conducive work place with easy accessibility for those with special needs Building a better tomorrow by grooming our current leaders for the next level of leadership Attract and retain individuals exhibiting talent in every possible perspective

Job Description
6-8 Years In-depth Experience on Linux OS (Redhat/Suse) Administration, Installation and Troubleshooting, Upgradation of Redhat or Suse Linux OS In-depth knowledge of HP/Dell/IBM Servers and Storage, with the ability to design and implement in large datacenter enviornment Strong knowledge on RHEL Virtualisation technologies. RAID Concepts Managing Physical and Logical volumes Filesystem Management Account and Security Management Advanced networking concepts Troubleshooting skills Performance monitoring and Tuning Expertise in Clustering Technologies like Veritas cluster and Redhat clustering is a must Backup and Recovery Methodologies Level2 expertise any other UNIX OS - Solaris or HPUX or AIX. Excellent communication skills in English.

http://www.cyberciti.biz/faq/vi-vim-editor-search-and-replace-howto/ http://nixcraft.com/linux-software/479-blocking-ports-linux.html

What is SELinux? Write a command to find all of the files which have been accessed within the last 10 days. What is LILO? What is Grub? Explain the difference between LILO and Grub What is NFS? What is NAMED? What is MySQLD? What is mysql? What is CVS?

Why You Shouldn't Use the root Login for everyday work? Describe the default partition scheme in Redhat Linux? Describe the default partition scheme in Solaris? What is the slice number? Describe all default mount point? What is boot block? What is logical block? Describe the process for adding a new hard disk to UNIX box? Describe the process for adding a new hard disk to Linux box? Describe the process for adding a new hard disk to Linux LVM to grow /home? Explain one major difference between a regular file system and a journaling file system? Define JFS Define UFS How do you lock and unlock user account / password? Describe RPM and command to install / remove / update Linux system? Explain difference between rpm and up2date command. Explain difference between rpm and apt-get command. Explain difference between rpm and yum command. Describe usage for pkgadd, pkginfo and pkgchk command How do you find files on UNIX or Linux system? Explain /etc/rc3.d Explain ntsysv or chkconfig command How do you get rid of process if kill PID is not working for you? What is the purpose of the command?

grep sed awk ifconfig netstat df du prtvtoc fdisk -l umaks getfacl setfacl sudo fsck probe-scsi vmstat Explain LVM

UNIX - LINUX Interview Questions and Answers :


1. How are devices represented in UNIX? All devices are represented by files called special files that are located in/dev directory. Thus, device files and other files are named and accessed in the same way. A 'regular file' is just an ordinary data file in the disk. A 'block special file' represents a device with characteristics similar to a disk (data transfer in terms of blocks). A 'character special file' represents a device with characteristics similar to a keyboard (data transfer is by stream of bits in sequential order).

2. What is 'inode'? All UNIX files have its description stored in a structure called 'inode'. The inode contains info about the file-size, its location, time of last access, time of last modification, permission and so on. Directories are also represented as files and have an associated inode. In addition to descriptions about the file, the inode contains pointers to the data blocks of the file. If the file is large, inode has indirect pointer to a block of pointers to additional data blocks (this

further

aggregates

for

larger

files).

block

is

typically

8k.

Inode consists of the following fields: File owner identifier File type File access permissions File access times Number of links File size Location of the file data

3. Brief about the directory representation in UNIX A Unix directory is a file containing a correspondence between filenames and inodes. A directory is a special file that the kernel maintains. Only kernel modifies directories, but processes can read directories. The contents of a directory are a list of filename and inode number pairs. When new directories are created, kernel makes two entries named '.' (refers to the directory itself) and '..' (refers to parent directory).

System call for creating directory is mkdir (pathname, mode). 4. What are the Unix system calls for I/O? open(pathname,flag,mode) - open file creat(pathname,mode) - create file close(filedes) - close an open file read(filedes,buffer,bytes) - read data from an open file write(filedes,buffer,bytes) - write data to an open file lseek(filedes,offset,from) - position an open file dup(filedes) - duplicate an existing file descriptor dup2(oldfd,newfd) - duplicate to a desired file descriptor fcntl(filedes,cmd,arg) - change properties of an open file ioctl(filedes,request,arg) - change the behaviour of an open file

The difference between fcntl anf ioctl is that the former is intended for any open file, while the latter is for device-specific operations.

5. How do you change File Access Permissions?

Every owner's owner's

file user group ID ID

has ( ( 16 16

following bit bit

attributes: integer integer ) )

File access mode word


'r w x -r w x- r w x'

(user r-read, To change

permission-group w-write, the access mode,

permission-others

permission) x-execute

we

use

chmod(filename,mode). 1:

Example

To change mode of myfile to 'rw-rw-r' (ie. read, write permission for user - read,write permission for group chmod(myfile,0664) Each operation is represented by discrete values
'r' is 4 'w' is 2 'x' is 1

only read

permission for others) we give the args as: .

Therefore, Example

for

'rw'

the

value

is

6(4+2). 2:

To change mode of myfile to 'rwxrr' we give the args as:


chmod(myfile,0744).

6. What are links and symbolic links in UNIX file system? A link is a second name (not a file) for a file. Links can be used to assign more than one name to a file, but cannot be used to assign a directory more than one name or link filenames on different computers.

Symbolic link 'is' a file that only contains the name of another file.Operation on the symbolic link is directed to the file pointed by the it.Both the limitations of links are eliminated in symbolic Commands for linking files are:
Link ln filename1 filename2 Symbolic link ln -s filename1 filename2

links.

7. What is a FIFO?

FIFO are otherwise called as 'named pipes'. FIFO (first-in-first-out) is a special file which is said to be data transient. Once data is read from named pipe, it cannot be read again. Also, data can be read only in the order written. It is used in interprocess communication where a process writes to one end of the pipe (producer) and the other reads from the other end (consumer).

8. How do you create special files like named pipes and device files?

The 1.

system

call

mknod

creates

special assigns

files

in

the new

following

sequence. inode,

kernel

2. sets the file type to indicate that the file is a pipe, directory or special file, 3. If it is a device file, it makes the other entries like major, minor device numbers. For example:

If the device is a disk, major device number refers to the disk controller and minor device number is the disk. 9. Discuss the mount and unmount system calls The privileged mount system call is used to attach a file system to a directory of another file system; the unmount system call detaches a file system. When you mount another file system on to your directory, you are essentially splicing one directory tree onto a branch in another directory tree. The first argument to mount call is the mount point, that is , a directory in the current file naming system. The second argument is the file system to mount to that point. When you insert a cdrom to your unix system's drive, the file system in the cdrom automatically mounts to /dev/cdrom in your system.

10. How does the inode map to data block of a file? Inode has 13 block addresses. The first 10 are direct block addresses of the first 10 data blocks in the file. The 11th address points to a one-level index block. The 12th address points to a two-level (double in-direction) index block. The 13th address points to a threelevel(triple in-direction)index block. This provides a very large maximum file size with efficient access to large files, but also small files are accessed directly in one disk read.

11. What is a shell?

A shell is an interactive user interface to an operating system services that allows an user to enter commands as character strings or through a graphical user interface. The shell converts them to system calls to the OS or forks off a process to execute the command. System call results and other information from the OS are presented to the user through an interactive interface. Commonly used shells are sh,csh,ks etc.

12. Brief about the initial process sequence while the system boots up. While booting, special process called the 'swapper' or 'scheduler' is created with Process-ID 0. The swapper manages memory allocation for processes and influences CPU allocation. The swapper inturn creates 3 children:

with

the process dispatcher, vhand and dbflush IDs 1,2 and 3 respectively.

This is done by executing the file /etc/init. Process dispatcher gives birth to the shell. Unix keeps track of all the processes in an internal data structure called the Process Table (listing command is ps -el). 13. What are various IDs associated with a process? Unix identifies each process with a unique integer called ProcessID. The process that executes the request for creation of a process is called the 'parent process' whose PID is 'Parent Process ID'. Every process is associated with a particular user called the 'owner' who has privileges over the process. The identification for the user is 'UserID'. Owner is the user who executes the process. Process also has 'Effective User ID' which determines the access privileges for accessing resources like files.

getpid() -process id getppid() -parent process id getuid() -user id geteuid() -effective user id

14. Explain fork() system call.

The `fork()' used to create a new process from an existing process. The new process is called the child process, and the existing process is called the parent. We can tell which is which by checking the return value from `fork()'. The parent gets the child's pid returned to him, but the child gets 0 returned to him.

15. Predict the output of the following program code


main() { fork(); printf("Hello World!"); }

Answer:
Hello World!Hello World!

Explanation: The fork creates a child that is a duplicate of the parent process. The child begins from the fork().All the statements after the call to fork() will be executed twice.(once by the parent process and other by child). The statement before fork() is executed only by the parent process. 16. Predict the output of the following program code
main() { fork(); fork(); fork(); printf("Hello World!"); }

Answer: "Hello Explanation: 2^n times where n is the number of calls to fork() 17. List the system calls used for process management: System calls Description World" will be printed 8 times.

fork() To create a new process exec() To execute a new program in a process wait() To wait until a created process completes its execution exit() To exit from a process execution getpid() To get a process identifier of the current process

getppid() To get parent process identifier nice() To bias the existing priority of a process brk() To increase/decrease the data segment size of a process.

18. How can you get/set an environment variable from a program? Getting the value of an environment variable is done by using `getenv()'. Setting the value of an environment variable is done by using `putenv()'.

19. How can a parent and child process communicate? A parent and child can communicate through any of the normal inter-process

communication schemes (pipes, sockets, message queues, shared memory), but also have some special ways to communicate that take advantage of their relationship as a parent and child. One of the most obvious is that the parent can get the exit status of the child.

20. What is a zombie? When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the child's exit status. To be able to get this information, the parent calls `wait()'; In the interval between the child terminating and the parent calling `wait()', the child is said to be a `zombie' (If you do `ps', the child will have a `Z' in its status field to indicate this.)

21. What are the process states in Unix? As a process executes it changes state according to its circumstances. Unix processes have the Running : Waiting : Stopped : The The The process process process is is has following either waiting been running for stopped, an or it is or by ready for a to states: run .

event usually

resource. a signal.

receiving

Zombie : The process is dead but have not been removed from the process table.

Mark, you've spent the last few years focused almost exclusively on helping new users move to Linux. You've also written some books on UNIX and Linux to help foster this migration. What are the most popular questions beginner Linux users ask? Mark: I'd have to divide the questions into three categories.

First, many beginning Linux users want to understand how to move from Windows to Linux.
Second, beginning Linux users often ask questions regarding file management such as file handling, permissions, and application installation. Third, beginner Linux users consistently ask me for help regardinginstallation and boot-up. These are the key categories. I find that once someone has a handle on these three, they are empowered sufficiently to address almost all other concerns.

Andrea: Let's start with Windows to Linux. I'm assuming they're looking for common ground between the two worlds? Mark: I wouldn't call it two worlds. The fact is that Xfce, Gnome, or KDE are unique, having many features and powerful functions. However, they are all reasonably similar to the interface experiences Windows users already have. So, my first tendency is to explain the obvious similarities, which in turn helps ease their minds and helps them acclimate quicker. Every GUI, whether X, OSX, Windows, KDE, etc. must convey a graphical form of the file hierarchy and allow file copying, deletion, and permissions settings. I usually provide an explanation how to get to the all important File Manager in Linux. If using the Gnome desktop for Linux you would look for an icon or label from your menu that states: Browse File System. Using the KDE you can often identify the file manager as a little "house" icon, or with the menu: Home. I also prefer to use this as an opportunity to explain how to get to a terminal/command prompt. In Gnome a shortcut for beginners is available by choosing Run Application from the main menu and typing commands. For KDE, you can find this under the System main menu labeled Terminal. Once you have access to type commands you can then get to your file manager and almost every other program or tool by typing the appropriate command. Most new users accept this since they quickly recognize the efficiency of this option. For Gnome File Manager, you would type: nautilus -browser For the KDE file manager (a part of the Konqueror browser) you type: konqueror --profile filemanagement Some Linux enthusiasts think the command prompt is not ever for Windows newbies. Unfortunately, many people forget that brand new Linux users typically do have a strong handle on technical things like typing commands or they've never had any experience with PCs such as those I help in Africa. So, the instructions I give are designed for helping BOTH audiences easily get acclimated. Most importantly, I never discount the cognitive capacity of my reader.

Andrea: At this point, where does the beginning user go? Mark: The next thing to share with the beginning user is the very important aspect of file permissions. It's vital that new users understand that in the Windows world they usually do not encounter file permissions. In the Linux world this is never the case. Files always include various levels of permissions, which is a strength of the Linux OS. Essential files are not accessible for accidental deletion or use by unauthorized users. This saved my neck a good many times when I started with Linux ten years ago. So my advice is this: while the new user has the file manager open, choose the File Permissions by highlighting a file and pressing the right mouse button. Then by choosing Permissions they get a good look at all of the options. Files always have three levels of permissions for three corresponding users. First, the three user audiences in Linux are: you the individual user, a select group of users, and the whole world of users. This is referred to as User, Group, andOthers. You can choose for each user audience a distinct level of file access. Three levels exist: Read, Write, and Execute. Obviously a forth exists which is no permission to read, write, or execute the file, which is rare. In most cases files are Read only, even to the user. If you want to modify the file, or delete the file, you need to change the permission for User to have Write access as well and so on. In any case I provide details regarding using a Graphical Interface to change permissions, and another article for using the command or terminal to change permissions (chmod).

Andrea: Okay, so now someone knows the basics of how to run a command, use file manager and change permissions. Anything else every beginning Linux user wants to know when switching from Windows? Mark: Yes, they want to know how to get an application on to their desktop toolbar. For instance when I install SuSe the terminal tool is buried and I always prefer to add an icon to the bottom toolbar. The easiest way to do this is to use the file search tool, identify where the actual application resides, then use the right mouse button to add it to the desktop. Then it's a simple matter of dragging-and-dropping the new icon to the toolbar. In Gnome, you can search for particular files using the Gnome Search Tool, often simply labeled on the main menu asSearch. In KDE, you can search for a file or application using the Kfind tool under the text Find Files under the main menu. Using these search tools you can look up an application. Once found, you then know the exact directory location and can easily add it to the desktop. For new users who want a fast way, I give them this command to use:

find / -name yourfile -type d -xdev (replace the word 'yourfile' with the name of an actual file or application) In Gnome, add a file, once you know where it exists, to the desktop by pressing the right mouse button while the pointer is over the desktop, and selecting Create Launcher. In KDE, you can quickly add an application to the desktop by pressing the right mouse button while the pointer is set over the desktop, then choosing Create New, then File, then Link to Application. Obviously, in both cases you need to then browse for the application, identify its location and save the change. You can then drag the icon to the toolbar.

Andrea: Well you covered a lot of the key beginner questions regarding moving to Linux. Are there any other vital commands beginning users always need to know? Mark: Absolutely. There are a whole slew of commands that new users tend to ask about. However the most essential ones always have to do with installing an application. Installing Linux applications today is far easier than most will admit. There are several ways to install a program, but the two most common ways include using an RPM (package manager) or using a TAR-GZ compressed file. For beginners, it's often easy for me to describe it this way: If you find an application you want to install and it's an RPM file, put it into its own directory on your Linux system. You can use the file manager to create a directory under your own user area. Copy the rpm file into the new directory, then using your file manager such as KDE you should usually be able to simply click on the icon for the .rpm file to start the package manager tool, which installs it for you. If you've instead found a .gz or .tar file that is a compressed version of your application, similar to using the ZIP/UNZIP tool for Windows, you need to place the file into a unique directory and then run this command: tar -xvzf *.gz This will uncompress the file into its own complete directory structure at which point you can find the main file and click on it from your file manager to activate the installation. The next question is where did the installation actually PUT THE APPLICATION! This varies but in many cases the application is now under your /usr/bin/ directory. For instance, install the Skype Linux gzip file and you end up with the application under /usr/bin/skype. You can then create a desktop icon for it by using the tips I said earlier. Just remember, most installed applications end up either under /usr/bin or under the specific directory under /home/username/directory (replace username with your username and directory for the directory you created). Sometimes, applications get a little unique such as installing OpenOffice, but in most cases things end up in either of these locations.

Andrea: What about the third category of most popular beginner questions Mark? Do users get stuck trying to install Linux and where do they encounter boot-up problems.

Mark: Yes, a few users unfortunately have installation problems. I say a few, since numerically almost everyone I meet installs their flavor without a hitch. However, in every two or three dozen new users there is always one person who gets stuck and stuck badly. In almost every single case the reason they get stuck has to do with incompatible hardwareor problems with a driver. I know what it takes to write device drivers. It's tough work, and for every Linux developer who's written device drivers I have a great respect for what you do... in my eyes these are the men and women who actually enable Linux! However, there are so many unique hardware chipsets, so many constantly changing specifications that sometimes the hardware you're using takes a lot of work to enable on your Linux. Most of the newest Linux flavors include plenty of drivers and the optional generic drivers that allow a beginner to get going. Right now the biggest complaint regards wireless LAN cards. As more and more device drivers for these are included in the newest flavor releases of Linux this issue should die down. Right now a lot of new users end up having to go download the device driver and try to install it themselves. Then you get into a little mess with trying to explain the NDISWrapper, etc. which often throws off new users. My advice is to use the most current flavor of Linux you can (don't expect the free version that came in a magazine pouch to give you a great deal of options). Full flavored versions tend to address the driver issue better by including many more. For those that prefer to have their Linux pre-burned on to CDs instead of doing it themselves, Edmunds is one of several reasonable sources. Here is some information if you're trying to get an internal modem to work. Here is some basic information if you're fiddling with a wireless card that might help you along with this link.

Andrea: Mark, what about boot-up issues? Mark: Oh, yes! Most of the time when someone approaches me with a "boot-up" problem it has to do with their desire toget a program automatically loaded on bootup instead of having to manually restart the process/program every time. This is easily resolved and the solution is almost always to go to the /etc/rc.d directory. Using this command: cd /etc/rc.d Then they should choose rc5.d which is your RUN LEVEL 5 boot parameter area. Again type: cd /rc5.d By the way, run level five is the standard run level when operating your Linux system. It's not important to get into the details of this, just to ensure beginners understand it exists. As they get more deeply into Linux it will become more important. Now, under /etc/rc.d/rc5.d you will find files with prefixes of the letters K or S. Seems strange to new users, but it's simple to understand if explained reasonably. The program you desire to load automatically on boot is most likely located in this directory and has a K prefix. The K means it does not automatically load on boot. Instead, you simply need to change the file to read prefix of S. You can use file manager to change the file name, or use a command/terminal to change directories and then type the command:

cp Kfilename Sfilename Now, I always tell a beginning user to reboot the Linux system. It's a bit overkill since you can restart the processes and pickup the changes, but it's simple and straightforward to do a reboot. Once rebooted, the program should load automatically. This is distinctly different when dealing with tools like telnet or ftp. These are network related processes and are enable differently. I have lots more details and examples under this brief article regarding configuring Linux.

Andrea: Are there any other major questions you keep getting regarding Linux use? Mark: Yes the final one is very common among brand new users but the answer is sometimes complex. People want to have access to their Windows files, often on another partition of their hard disk. This is enabled by mounting the Windows partition. Beginning users are often befuddled by this because they don't know to look for the word "mount" to enable their Windows access. In most Linux versions you can click on the desktop icon labeled "My Computer" or "System" where you see a list of all of the drives. You can then mount a drive by clicking the right mouse button over the appropriate drive letter. Most of the time Windows resides on Hda1. Hard disk partition a1. You can also try forcing mount for most drives by a series of basic steps: First check to see what is already mounted. Type the command: mount Second, if your Windows hard disk did not show up, you might try creating a windows mount. Type the command: mkdir /mnt/win Now use this command to mount your WindowsXP or NT: mount -t ntfs /dev/hda1 /mnt/win This process usually works for most shared disk scenerios.

Andrea: What about beginners accessing their Windows programs? Mark: This is a lot more complex but there is certainly a volume of information on the Internet regarding running almost every Windows related program using the Wine tool. Wine allows most programs that run under Windows to also run under Linux. Obviously success is predicated upon many things, including a lot more user intervention. You can find some additional basic information regarding Wine on this page and on this website.

loperWorks Technical topics Linux Technical library

Learn Linux, 101: Runlevels, shutdown, and reboot


Bring your system to life
Ian Shields, Senior Programmer, IBM Summary: Learn to shut down or reboot your Linux system, warn users that the system is going down, and switch to a more or less restrictive runlevel. You can use the material in this article to study for the LPI 101 exam for Linux system administrator certification, or just to learn about shutting down, rebooting, and changing runlevels. 18 Sep 2012 - This article updated to include material for the LPI Exam 101: Objective Changes as of July 2, 2012. Major updates occur in these sections: Beyond Init, Upstart, Systemd, and Resources. View more content in this series Date: 18 Sep 2012 (Published 05 Jan 2011) Level: Intermediate PDF: A4 and Letter (358 KB | 16 pages)Get Adobe Reader Also available in: Korean Russian Japanese Portuguese Activity: 116701 views Comments: 8 (View | Add comment - Sign in)

Average rating (103 votes) Rate this article


About this series
This series of articles helps you learn Linux system administration tasks. You can also use the material in these articles to prepare for Linux Professional Institute Certification level 1 (LPIC-1) exams. See our developerWorks roadmap for LPIC-1 for a description of and link to each article in this series. The roadmap is in progress and reflects the latest (April 2009 with minor updates in July 2012) objectives for the LPIC-1 exams: as we complete articles, we add them to the roadmap. In the meantime, though, you can find earlier versions of similar material, supporting previous LPIC-1 objectives prior to April 2009, in our LPI certification exam prep tutorials.

Overview
In this article, learn to shut down or reboot your Linux system, warn users that the system is going down, and switch to single-user mode or a more or less restrictive runlevel. Learn to: Set the default runlevel Change between runlevels Change to single-user mode Shut down or reboot the system from the command line Alert users about major system events, including switching to another runlevel Terminate processes properly Unless otherwise noted, the examples in this article use a Fedora 8 system with a 2.6.26 kernel. The upstart examples use Fedora 13 with a 2.6.34 kernel, or Ubuntu 10.10 with a 2.6.35 kernel. The systemd examples use Fedora 17 with a 3.4.4 kernel. Your results on other systems may differ.

This article helps you prepare for Objective 101.3 in Topic 101 of the Linux Professional Institute's Junior Level Administration (LPIC-1) exam 101. The objective has a weight of 3. Note: This article includes material for the LPI Exam 101: Objective Changes as of July 2, 2012.

Prerequisites
To get the most from the articles in this series, you should have a basic knowledge of Linux and a working Linux system on which to practice the commands covered in this article. Sometimes different versions of a program will format output differently, so your results may not always look exactly like the listings and figures shown here. In particular, the newer upstart and systemd systems are changing many things that might be familiar to users of the traditional System V init process (see Beyond Init for details). This article is directed primarily at the traditional System V init process, with brief overviews of the how upstart and systemd differ. Back to top

Runlevels
Connect with Ian

Ian is one of our most popular and prolific authors. Browse all of Ian's articles on developerWorks. Check out Ian's profile and connect with him, other authors, and fellow readers in My developerWorks. Runlevels define what tasks can be accomplished in the current state (or runlevel) of a Linux system. Every Linux system supports three basic runlevels, plus one or more runlevels for normal operation. The basic runlevels are shown in Table 1. Table 1. Linux basic runlevels
Level Purpose

Shut down (or halt) the system

Single-user mode; usually aliased as s or S

Reboot the system

Beyond the basics, runlevel usage differs among distributions. One common usage set is shown in Table 2. Table 2. Other common Linux runlevels
Level Purpose

Multiuser mode without networking

Multiuser mode with networking

Multiuser mode with networking and the X Window System

The Slackware distribution uses runlevel 4 instead of 5 for a full system running the X Window system. Debian and derivatives, such as Ubuntu, use a single runlevel for any multiuser mode, typically runlevel 2. Be sure to consult the documentation for your distribution. Back to top

Default runlevel
When a Linux system starts, the default runlevel is determined from the id: entry in /etc/inittab. Listing 1 illustrates a typical entry for a system such as Fedora 8 or openSUSE 11.2, both of which use runlevel 5 for the X Window System. Listing 1. Default runlevel in /etc/inittab
[root@pinguino ~]# grep "^id:" /etc/inittab id:5:initdefault:

Edit this value if you want your system to start in a different runlevel, say runlevel 3. Back to top

Changing runlevels
There are several ways to change runlevels. To make a permanent change, you can edit /etc/inittab and change the default level as you just saw above. If you only need to bring the system up in a different runlevel for one boot, you can do this. For example, suppose you just installed a new kernel and need to build some kernel modules after the system booted with the new kernel, but before you start the X Window System. You might want to bring up the system in runlevel 3 to accomplish this. You do this at boot time by editing the kernel line (GRUB) or adding a parameter after the selected system name (LILO). Use a single digit to specify the desired runlevel (3, in this case). We'll illustrate the process with a GRUB example. Suppose your /boot/grub/menu.lst file contains the stanza shown in Listing 2. Listing 2. Typical GRUB stanza to boot Fedora 8
title Fedora (2.6.26.8-57.fc8) root (hd0,5) kernel /boot/vmlinuz-2.6.26.8-57.fc8 ro root=LABEL=FEDORA8 rhgb quiet initrd /boot/initrd-2.6.26.8-57.fc8.img

To bring this system up in runlevel 3, wait till the boot entries are displayed, select this entry and enter 'e' to edit the entry. Depending on your GRUB options, you may need to press a key to display the boot entries and also enter 'p' and a password to unlock editing. The GRUB screen on our Fedora 8 system looks like Figure 1.

Figure 1. Selecting a boot choice in GRUB

In this example, you should now see the root, kernel, and initrd lines displayed. Move the cursor to the line starting with "kernel" and press 'e' to edit the line. The GRUB screen on our Fedora 8 system now looks like Figure 2. Figure 2. Selecting the kernel entry for editing

Finally, move the cursor to the end of the line, and add a space and the digit '3'. You may remove 'quiet' if you wish, or modify any other parameters as needed. The GRUB screen on our Fedora 8 system now looks like Figure 3.

Figure 3. Setting the starting runlevel to 3

Finally, press Enter to save the changes, then type 'b' to boot the system. Note: The steps for doing this using LILO or GRUB2 differ from those for GRUB, but the basic principle of editing the way the kernel is started remains. Even GRUB screens on other systems or other distributions may look quite different to those shown here. Prompts will usually be available to help you. Once you have finished your setup work in runlevel 3, you will probably want to switch to runlevel 5. Fortunately, you do not need to reboot the system. You can use the telinit command to switch to another runlevel. Use the runlevel command to show both the previous runlevel and the current one. If the first output character is 'N', the runlevel has not been changed since the system was booted. Listing 3 illustrates verifying and changing the runlevel. Listing 3. Verifying and changing the runlevel
[root@pinguino ~]# runlevel N 3 [root@pinguino ~]# telinit 5

After you enter telinit 5 you will see several messages flash by and your display will switch to the configured graphical login screen. Open a terminal window and verify that the runlevel has been changed as shown in Listing 4. Listing 4. Confirming the new runlevel
[root@pinguino ~]# runlevel 3 5

If you use the ls command to display a long listing of the telinit command, you will see that it really is a symbolic link to theinit command. We illustrate this in Listing 5

Listing 5. telinit is really a symbolic link to init


[root@pinguino ~]# ls -l $(which telinit) lrwxrwxrwx 1 root root 4 2008-04-01 07:50 /sbin/telinit -> init

The init executable knows whether it was called as init or telinit and behaves accordingly. Since init runs as PID 1 at boot time, it is also smart enough to know when you subsequently invoke it using init rather than telinit. If you do, it will assume you want it to behave as if you had called telinit instead. For example, you may use init 5 instead of telinit 5 to switch to runlevel 5. Back to top

Single-user mode
In contrast to personal computer operating systems such as DOS or Windows, Linux is inherently a multiuser system. However, there are times when that can be a problem, such as when you need to recover a major filesystem or database, or install and test some new hardware. Runlevel 1, or single-user mode, is your answer for these situations. The actual implementation varies by distribution, but you will usually start in a shell with only a minimal system. Usually there will be no networking and no (or very few) daemons running. On some systems, you must authenticate by logging in, but on others you go straight into a shell prompt as root. Single-user mode can be a lifesaver, but you can also destroy your system, so always be careful whenever you are running with root authority. Reboot to normal multiuser mode as soon as you are done. As with switching to regular multiuser runlevels, you can also switch to single-user mode using telinit 1. As noted in Table 1, 's' and 'S' are aliases for runlevel 1, so you could, for example, use telinit s instead. Back to top

Clean shutdown
While you can use telinit or init to stop multiuser activity and switch to single-user mode, this can be rather abrupt and cause users to lose work and processes to terminate abnormally. The preferred method to shut down or reboot the system is to use the shutdown command, which first sends a warning message to all logged-in users and blocks any further logins. It then signals init to switch runlevels. The init process then sends all running processes a SIGTERM signal, giving them a chance to save data or otherwise properly terminate. After 5 seconds, or another delay if specified, init sends a SIGKILL signal to forcibly end each remaining process. By default, shutdown switches to runlevel 1 (single-user mode). You may specify the -h option to halt the system, or the -roption to reboot. A standard message is issued in addition to any message you specify. The time may be specified as an absolute time in hh:mm format, or as a relative time, n, where n is the number of minutes until shutdown. For immediate shutdown, use now, which is equivalent to +0. If you have issued a delayed shutdown and the time has not yet expired, you may cancel the shutdown by pressing Ctrl-c if the command is running in the foreground, or by issuing shutdown with the -c option to cancel a pending shutdown. Listing 6 shows several examples of the use of shutdown, along with ways to cancel the command. Listing 6. Shutdown examples
[root@pinguino ~]# shutdown 5 File system recovery needed

Broadcast message from root (pts/1) (Tue Jan

4 08:05:24 2011):

File system recovery needed The system is going DOWN to maintenance mode in 5 minutes! ^C Shutdown cancelled. [root@pinguino ~]# shutdown -r 10 Reloading updated kernel& [1] 18784 [root@pinguino ~]# Broadcast message from root (pts/1) (Tue Jan 4 08:05:53 2011): Reloading updated kernel The system is going DOWN for reboot in 10 minutes! [root@pinguino ~]# fg shutdown -r 10 Reloading updated kernel ^C Shutdown cancelled. [root@pinguino ~]# shutdown -h 23:59& [1] 18788 [root@pinguino ~]# shutdown -c Shutdown cancelled. [1]+ Done shutdown -h 23:59

You may have noticed that our last example did not cause a warning message to be sent. If the time till shutdown exceeds 15 minutes, then the message is not sent until 15 minutes before the event as shown in Listing 7. Listing 7 also shows the use of the -t option to increase the default delay between SIGTERM and SIGKILL signals from 5 seconds to 60 seconds. Listing 7. Another shutdown example
[root@pinguino ~]# date;shutdown -t60 17 Time to do backups& Tue Jan 4 08:12:55 EST 2011 [1] 18825 [root@pinguino ~]# date Tue Jan 4 08:14:13 EST 2011 [root@pinguino ~]# Broadcast message from root (pts/1) (Tue Jan 4 08:14:55 2011): Time to do backups The system is going DOWN to maintenance mode in 15 minutes!

If you do cancel a shutdown, you should use the wall command to send a warning to all users alerting them to the fact that the system is not going down. As we said earlier, it is also possible to use telinit (or init) to shut down or reboot the system. As with other uses oftelinit, no warning is sent to users, and the command takes effect immediately, although there is still a delay between SIGTERM and SIGKILL signals. For additional options of telinit, init, and shutdown, consult the appropriate man pages. Back to top

Halt, reboot, and poweroff


You should know about a few more commands related to shutdown and reboot. The haltcommand halts the system. The poweroff command is a symbolic link to the halt command, which halts the system and then attempts to power it off.

The rebootcommand is another symbolic link to the halt command, which halts the system and then reboots it. If any of these are called when the system is not in runlevel 0 or 6, then the corresponding shutdown command will be invoked instead. For additional options that you may use with these commands, as well as more detailed information on their operation, consult the man page. Back to top

/etc/inittab
By now, you may be wondering why pressing Ctrl-Alt-Delete on some systems causes a reboot, or how all this runlevel stuff is configured. Remember the id field in /etc/inittab? Well, there are several other fields in /etc/inittab, along with a set of init scripts in directories such as rc1.d or rc5.d, where the digit identifies the runlevel to which the scripts in that directory apply. Listing 8 shows the full inittab from our Fedora 8 system. Listing 8. Full inittab from Fedora 8
# # inittab # # # Author: # #

This file describes how the INIT process should set up the system in a certain run-level. Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org> Modified for RHS Linux by Marc Ewing and Donnie Barnes

# Default runlevel. The runlevels used by RHS are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # id:5:initdefault: # System initialization. si::sysinit:/etc/rc.d/rc.sysinit l0:0:wait:/etc/rc.d/rc l1:1:wait:/etc/rc.d/rc l2:2:wait:/etc/rc.d/rc l3:3:wait:/etc/rc.d/rc l4:4:wait:/etc/rc.d/rc l5:5:wait:/etc/rc.d/rc l6:6:wait:/etc/rc.d/rc 0 1 2 3 4 5 6

# Trap CTRL-ALT-DELETE ca::ctrlaltdel:/sbin/shutdown -t3 -r now # When our UPS tells us power has failed, assume we have a few minutes # of power left. Schedule a shutdown for 2 minutes from now. # This does, of course, assume you have powerd installed and your # UPS connected and working correctly. pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down" # If power was restored before the shutdown kicked in, cancel it. pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled" # Run gettys in standard runlevels 1:2345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5

6:2345:respawn:/sbin/mingetty tty6 # Run xdm in runlevel 5 x:5:respawn:/etc/X11/prefdm -nodaemon

As usual, lines starting with # are comments. Other lines have several fields with the following format:
id:runlevels:action:process

id is a unique identifier of one to four characters. Older versions limited this to two characters, so you will often see only two characters used. runlevels lists the runlevels for which the action for this id should be taken. If no runlevels are listed, do the action for all runlevels. action describes which of several possible actions should be taken process tells which process, if any, should be run when the action on this line is performed. Some of the common actions that may be specified in /etc/inittab are shown in Table 3. See the man pages for inittab for other possibilities. Table 3. Some common inittab actions
Action Purpose

respawn

Restart the process whenever it terminates. Usually used for getty processes, which monitor for logins.

wait

Start the process once when the specified runlevel is entered and wait for its termination before init proceeds.

once

Start the process once when the specified runlevel is entered.

initdefault Specifies the runlevel to enter after system boot.

ctrlaltdel

Execute the associated process when init receives the SIGINT signal, for example, when someone on the system console presses CTRLALT-DEL.

Listing 9 shows just the entry for Ctrl-Alt-Delete from Listing 8. So now you see why pressing CtrlAlt-Delete causes the system to be rebooted. Listing 9. Trapping Ctrl-Alt-Delete
# Trap CTRL-ALT-DELETE ca::ctrlaltdel:/sbin/shutdown -t3 -r now

Back to top

Initialization scripts
You may have noticed several lines in Listing 8, such as
l5:5:wait:/etc/rc.d/rc 5

In this example, init will run the /etc/rc.d/rc script (or command) with the parameter of 5 whenever runlevel 5 is entered.init will wait until this command completes before doing anything else. These scripts used by init when starting the system, changing runlevels, or shutting down are typically stored in the /etc/init.d or /etc/rc.d directory. A series of symbolic links in the rcn.d directories, one directory for each runlevel n, control whether a script is started when entering a runlevel or stopped when leaving it. These links start with either a K or an S, followed by a two-digit number and then the name of the service, as shown in Listing 10. Listing 10. Init scripts
[root@pinguino ~]# find /etc -path "*rc[0-9]*.d/???au*" /etc/rc.d/rc2.d/S27auditd /etc/rc.d/rc2.d/K72autofs /etc/rc.d/rc4.d/S27auditd /etc/rc.d/rc4.d/S28autofs /etc/rc.d/rc5.d/S27auditd /etc/rc.d/rc5.d/S28autofs /etc/rc.d/rc0.d/K72autofs /etc/rc.d/rc0.d/K73auditd /etc/rc.d/rc6.d/K72autofs /etc/rc.d/rc6.d/K73auditd /etc/rc.d/rc1.d/K72autofs /etc/rc.d/rc1.d/K73auditd /etc/rc.d/rc3.d/S27auditd /etc/rc.d/rc3.d/S28autofs [root@pinguino ~]# cd /etc/rc.d/rc5.d [root@pinguino rc5.d]# ls -l ???a* lrwxrwxrwx 1 root root 16 2008-04-07 11:29 S27auditd -> ../init.d/auditd lrwxrwxrwx 1 root root 16 2008-04-01 07:51 S28autofs -> ../init.d/autofs lrwxrwxrwx 1 root root 15 2008-04-01 14:03 S44acpid -> ../init.d/acpid lrwxrwxrwx 1 root root 13 2008-04-01 07:50 S95atd -> ../init.d/atd lrwxrwxrwx 1 root root 22 2008-04-01 07:54 S96avahi-daemon -> ../init.d/avahi-daemon lrwxrwxrwx 1 root root 17 2008-11-17 13:40 S99anacron -> ../init.d/anacron

Here you see that the audit and autofs services have Knn entries in all runlevels and Snn entries for both in runlevels 3 and 5. The S indicates that the service is started when that runlevel is entered, while the K entry indicates that it should be stopped. Thenn component of the link name indicates the priority order in which the service should be started or stopped. In this example,audit is started before autofs, and it is stopped later. Consult the man pages for init and inittab for more information. Back to top

Beyond Init
As we have seen here, the traditional method of booting a Linux system is based on the UNIX System V init process. It involves loading an initial RAM disk (initrd) and then passing control to a program called init, a program that is usually installed as part of the sysvinit package. The init program is the first process in the system and has PID (Process ID) 1. It runs a series of scripts in a predefined order to bring up the system. If something that is expected is not available, the init process typically waits until it is. While this worked adequately for systems where everything is known and connected when the system starts, modern systems with hot-pluggable devices, network file systems, and even network interfaces that may not be available at start time present new challenges. Certainly, waiting for hardware that may not come available for a long time, or even just a relatively long time, is not desirable. In the following sections of this article we will describe two alternatives to System V init, upstart and systemd. Back to top

Upstart
A new initialization process called upstart was first introduced in Ubuntu 6.10 ("Edgy Eft") in 2006. Fedora 9 through 14 and Red Hat Enterprise Linux (RHEL) 6 use upstart, as do distributions derived from these. Upstart has now supplanted the init process in Ubuntu among others, although vestiges of init remain and the full power of upstart may not be realized for some time yet. In contrast to the static set of init scripts used in earlier systems, the upstart system is driven by events. Events may be triggered by hardware changes, starting or stopping or tasks, or by any other process on the system. Events are used to trigger tasks orservices, collectively known as jobs. So, for example, connecting a USB drive might cause the udev service to send a block-deviceadded event, which would cause a defined task to check /etc/fstab and mount the drive if appropriate. As another example, an Apache web server may be started only when both a network and required filesystem resources are available. The upstart initialization program replaces /sbin/init. Upstart jobs are defined in the /etc/init directory and its subdirectories. The upstart system will currently process /etc/inittab and System V init scripts. On systems such as recent Fedora releases, /etc/inittab is likely to contain only the id entry for the initdefault action. Recent Ubuntu systems do not have /etc/inittab by default, although you can create one if you want to specify a default runlevel. Upstart also has the initctl command to allow interaction with the upstart init daemon. This allows you to start or stop jobs, list jobs, get status of jobs, emit events, restart the init process, and so on. Listing 11 shows how to use initctl to obtain a list of upstart jobs on a Fedora 13 system. Listing 11. Interacting with upstart init daemon using initctl
[ian@echidna ~]$ initctl list rc stop/waiting tty (/dev/tty3) start/running, tty (/dev/tty2) start/running, tty (/dev/tty6) start/running, tty (/dev/tty5) start/running,

process process process process

1486 1484 1492 1490

tty (/dev/tty4) start/running, process 1488 plymouth-shutdown stop/waiting control-alt-delete stop/waiting system-setup-keyboard start/running, process 1000 readahead-collector stop/waiting vpnc-cleanup stop/waiting quit-plymouth stop/waiting rcS stop/waiting prefdm start/running, process 1479 init-system-dbus stop/waiting ck-log-system-restart stop/waiting readahead stop/waiting ck-log-system-start stop/waiting start-ttys stop/waiting readahead-disable-services stop/waiting ck-log-system-stop stop/waiting rcS-sulogin stop/waiting serial stop/waiting

To learn more about upstart, see Resources. Back to top

Systemd
Another new initialization system called systemd is also emerging. Systemd was developed by Lennart Poettering in early 2010. He described the rationale and design in a blog post (see Resources. It has been adopted for Fedora 15, openSUSE 12.1 and Mandriva 2011 among others. Many daemon processes communicate using sockets. In order to gain speed and enhance parallelism in the system startup, systemd creates these sockets at startup, but only starts the associated task when a connection request for services on that socket is received. In this way, services can be started only when they are first required and not necessarily at system initialization. Services that need some other facility will block until it is available, so only those services that are waiting for some other process need block while that process starts. Extending the idea of waiting for services systemd uses autofs to define mount points, so the mount point for a file system is available, but the actual mount may be delayed until some process attempts to open a file on the file system or otherwise use it. These ideas not only delay startup of services until needed, they also reduce the need for dependency checking between services, as the interface for the service can be ready long before the service itself needs to be available. Like upstart, systemd can process existing initialization from /etc/inittab. It can also process /etc/fstab to control file system mounting. Native systemd initialization revolves around the concept of units, which can be grouped into control groups orcgroups. Service units are daemons that can be started, stopped, restarted, reloaded. Socket units encapsulate a socket in the file-system or on the Internet. Device units encapsulate a device in the Linux device tree. Mount units encapsulate a mount point in the file system hierarchy. Automount units encapsulate an automount point in the file system hierarchy. Target units group other units together, providing a single control unit for multiple other units. Snapshot units reference other units and can be used to save and roll back the state of all services and units of the init system, for example during suspend. Units are configured using a configuration file which includes the unit type as a suffix. For example, cups.service, rpcbind.socket or getty.target. The location of system configuration files, for example /etc/systemd/system can be determined using the pkg-config command as shown in Listing 11 which shows the location on a Fedora 17 system. Systemd also checks /usr/local/lib/systemd/system and /usr/lib/systemd/system for configuration information.

Listing 12. Locating the systemd system configuration directory


[ian@attic4 ~]$ pkg-config systemd --variable=systemdsystemconfdir /etc/systemd/system

The systemctl command allows you to interrogate and control the systemd daemon, including starting and stopping units or listing their status. Listing 13 illustrates the use of systemctl to display the status of systemd units. Listing 13. Partial output from systemctl
[ian@attic4 ~]$ systemctl UNIT proc-sys...misc.automount sys-devi...et-eth0.device sys-devi...da-sda1.device sys-devi...a-sda10.device sys-devi...a-sda11.device sys-devi...a-sda12.device sys-devi...da-sda2.device ... systemd-...ssions.service systemd-...-setup.service tcsd.service udev-settle.service udev-trigger.service udev.service udisks2.service upower.service avahi-daemon.socket cups.socket ... syslog.target systemd-...ted-ntp.target systemd-...ead-done.timer systemd-...es-clean.timer LOAD ACTIVE SUB JOB = = = = --no-pager LOAD ACTIVE loaded active loaded active loaded active loaded active loaded active loaded active loaded active loaded loaded loaded loaded loaded loaded loaded loaded loaded loaded loaded loaded loaded loaded active active failed active active active active active active active active active active active

SUB running plugged plugged plugged plugged plugged plugged exited exited failed exited exited running running running listening running active active elapsed waiting

JOB DESCRIPTION Arbitrary Executable File RTL8111/8168B PCI Express WDC_WD6401AALS-00L3B2 WDC_WD6401AALS-00L3B2 WDC_WD6401AALS-00L3B2 WDC_WD6401AALS-00L3B2 WDC_WD6401AALS-00L3B2 Permit User Sessions Setup Virtual Console LSB: Init script for TCSD udev Wait for Complete Dev udev Coldplug all Devices udev Kernel Device Manager Storage Daemon Daemon for power managemen Avahi mDNS/DNS-SD Stack Ac CUPS Printing Service Sock Syslog Network Time Protocol Stop Read-Ahead Data Colle Daily Cleanup of Temporary

Reflects whether the unit definition was properly loaded. The high-level unit activation state, i.e. generalization of SUB. The low-level unit activation state, values depend on unit type. Pending job for the unit.

132 units listed. Pass --all to see inactive units, too.

To learn more about systemd, see Resources. This completes your introduction to Linux runlevels, shutdown, and reboot.

Software testing - Questions and Answers - Linix / Unix 1. Q. How do you list files in a directory? A. ls - list directory contents ls l (-l use a long listing format)

2. Q. How do you list all files in a directory, including the hidden files? A. ls -a (-a, do not hide entries starting with .) 3. Q. How do you find out all processes that are currently running? A. ps -f (-f does full-format listing.) 4. Q. How do you find out the processes that are currently running or a particular user? A. ps -au Myname (-u by effective user ID (supports names)) (a - all users) 5. Q. How do you kill a process? A. kill -9 8 (process_id 8) or kill -9 %7 (job number 7) kill -9 -1 (Kill all processes you can kill.) killall - kill processes by name most (useful - killall java) 6. Q. What would you use to view contents of the file? A. less filename cat filename pg filename pr filename more filename most useful is command: tail file_name - you can see the end of the log file. 7. Q. What would you use to edit contents of the file? A. vi screen editor or jedit, nedit or ex line editor 8. Q. What would you use to view contents of a large error log file? A. tail -10 file_name ( last 10 rows) 9. Q. How do you log in to a remote Unix box? A. Using telnet server_name or ssh -l ( ssh - OpenSSH SSH client (remote login program)) 10.Q. How do you get help on a UNIX terminal? A. man command_name info command_name (more information) 11.Q. How do you list contents of a directory including all of its subdirectories, providing full details and sorted by modification time? A. ls -lac -a all entries -c by time 12.Q. How do you create a symbolic link to a file (give some reasons of doing so)?

A. ln /../file1 Link_name Links create pointers to the actual files, without duplicating the contents of the files. That is, a link is a way of providing another name to the same file. There are two types of links to a file:Hard link, Symbolic (or soft) link; 13.Q. What is a filesystem? A. Sum of all directories called file system. A file system is the primary means of file storage in UNIX. File systems are made of inodes and superblocks. 14.Q. How do you get its usage (a filesystem)? A. By storing and manipulate files. 15.Q. How do you check the sizes of all users home directories (one command)? A. du -s df

The du command summarizes disk usage by directory. It recurses through all subdirectories and shows disk usage by each subdirectory with a final total at the end.

Q. in current directory A. ls -ps (p- directory; s - size) 16.Q. How do you check for processes started by user 'pat'? A. ps -fu pat (-f -full_format u -user_name )

17.Q. How do you start a job on background? A. bg %4 (job 4)

18 Q. What utility would you use to replace a string '2001' for '2002' in a text file? A. Grep, Kde( works on Linux and Unix)

19. Q. What utility would you use to cut off the first column in a text file? A. awk, kde 20. Q. How to copy file into directory? A. cp /tmp/file_name . (dot mean in the current directory) 21. Q. How to remove directory with files? A. rm -rf directory_name 22. Q. What is the difference between internal and external commands? A. Internal commands are stored in the; same level as the operating system while external

commands are stored on the hard disk among the other utility programs. 23. Q. List the three main parts of an operating system command: A. The three main parts are the command, options and arguments. 24 Q. What is the difference between an argument and an option (or switch)? A. An argument is what the command should act on: it could be a filename, directory or name. An option is specified when you want to request additional information over and above the basic information each command supplies. 25. Q. What is the purpose of online help? A. Online help provides information on each operating system command, the syntax, the options, the arguments with descriptive information. 26. Q. Name two forms of security. A. Two forms of security are Passwords and File Security with permissions specified. 27. Q. What command do you type to find help about the command who? A. $ man who 28. Q. What is the difference between home directory and working directory? A. Home directory is the directory you begin at when you log into the system. Working directory can be anywhere on the system and it is where you are currently working. 29. Q. Which directory is closer to the top of the file system tree, parent directory or current directory? A. The parent directory is above the current directory, so it is closer to the root or top of the file system. 30. Q. 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? A. a) $ payable/supplier/april b) $ /business/acctg/payable/supplier/april 31. Q. 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? A. a) ls *2 b) ls aid.* c) ls help.? 32. Q. What are two subtle differences in using the more and the pg commands? A. With the more command you display another screenful by pressing the spacebar, with pg you press the return key. The more command returns you automatically to the UNIX

shell when completed, while pg waits until you press return. 33. Q. When is it better to use the more command rather than cat command? A. It is sometimes better to use the more command when you are viewing a file that will display over one screen. 34. Q. What are two functions the move mv command can carry out? A. The mv command moves files and can also be used to rename a file or directory. 35. Q. Name two methods you could use to rename a file. A. Two methods that could be used: a. use the mv command b. copy the file and give it a new name and then remove the original file if no longer needed. 36. 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 A. a) mv Bteam.abc Bteam.OO3. b) cat Gteam.win -or- more Gteam.win rm Gteam. win c) mkdir boys mkdir girls d) mv Bteam* boys e) mv Gteam* girls f) cd girls cp Gteam.OO1 Gteam.OO4 g) There are several ways to do this. Remember that we are currently in the directory /soccer/girls. cp ../boys/Bteam.OO2 Gteam.OO5 or cd ../boys cp Bteam.OO2 ../girls/Gteam.OO5 37. Q. Draw a picture of the final directory structure for the "soccer" directory, showing all the files and directories. 38. Q. 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 A. 1. 1.1 double-dot or .. 1.2 asterisk or * 1.3 question or ? 1.4 double greater than sign: >> 1.5 the less than sign or < 39. Q. List all the files beginning with A A. To list all the files beginning with A command: ls A* 40. Q. Which of the quoting or escape characters allows the dollar sign ($) to retain its special meaning? A. The double quote (") allows the dollar sign ($) to retain its special meaning. Both the backslash (\) and single quote (') would remove the special meaning of the dollar sign. 41. Q. 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 A. A shortcut method would be: mv file?.txt newdir 42. Q. List two ways to create a new file: A. a. Copy a file to make a new file. b. Use the output operator e.g. ls -l > newfile.txt 43. Q. What is the difference between > and >> operators? A. The operator > either overwrites the existing file (WITHOUT WARNING) or creates a new file. The operator >> either adds the new contents to the end of an existing file or creates a new file. 44. Write the command to do the following: 44.1 Redirect the output from the directory listing to a printer. 44.2 Add the file efg.txt to the end of the file abc.txt. 44.3 The file testdata feeds information into the file called program 44.4 Observe the contents of the file called xyz.txt using MORE. 44.5 Observe a directory listing that is four screens long. A. 44.1 ls > lpr 44.2 cat efg.txt >> abc.txt 44.3 program < testdata 44.4 more < xyz.txt 44.5 ls > dirsave | more

45. Q. How do you estimate file space usage

A. Use du command (Summarize disk usage of each FILE, recursively for directories.) Good to use arguments du -hs (-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) (-s, --summarize display only a total for each argument) 46. Q. How can you see all mounted drives? A. mount -l 47. Q. How can you find a path to the file in the system? A. locate file_name (locate - list files in databases that match a pattern) 48. Q. What Linux HotKeys do you know? A. Ctrl-Alt-F1 Exit to command prompt Ctrl-Alt-F7 or F8 Takes you back to KDE desktop from command prompt Crtl-Alt-Backspace Restart XWindows Ctrl-Alt-D Show desktop 49. Q. What can you tell about the tar Command? A. The tar program is an immensely useful archiving utility. It can combine an entire directory tree into one large file suitable for transferring or compression. 50. Q. What types of files you know? A. Files come in eight flavors: Normal files Directories Hard links Symbolic links Sockets Named pipes Character devices Block devices 51. Q. How to copy files from on PC to another on the same network A. Use the following command:scp yur_file you_login@your_IP example: copy .conf file from your PC to alex computerscp /etc/X11/xorg.conf alex@10.0.10.169: 52. Q. Please describe information below: 1 dotpc 9 dotpc 1 dotpc 11 7 12 5 11 1 dotpc dotpc dotpc dotpc dotpc dotpc dotpc dotpc dotpc dotpc dotpc dotpc dotpc dotpc dotpc 102 Jul 18 2003 file.buf 4096 Oct 21 09:34 bin 20 Mar 21 15:00 client -> client4096 4096 4096 4096 4096 644836 Sep Dec Oct Dec Mar Mar 2 14 21 7 21 22 2005 12:13 09:41 14:22 15:54 09:53 client-2.8.9 data docs etc client-2.9.5 client-2.9.5.tar.gz

-rw-rw-r-drwxr-xr-x lrwxrwxrwx 2.9.5 drwxrwxr-x drwxrwxr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x -rw-r--r--

A. This is a result of command $ls -l we have two files, 6 directories and one link to client-2.9.5 directory. There is number of files in every directory, size and data of last change.

53. Q. If you would like to run two commands in sequence what operators you can use? A. ; or && the difference is: if you separate commands with ; second command will be run automatically. if you separate commands with && second command will be run only in the case the first was run successfully. 54. Q. How you will uncompress the file? A. Use tar command (The GNU version of the tar archiving utility): tar -zxvf file_name.tar.gz 55. Q.How do you execute a program or script, my_script in your current directoty? A. ./my_script 56. Q.How to find current time configuration in the file my_new.cfg A. grep time my_new.cfg Grep searches the named input files (or standard input if no files are named, or the file name - is given) for lines containing a match to the given pattern. Q. What does grep() stand for? A. General Regular Expression Parser. 57. Q. What does the top command display? A. Top provides an ongoing look at processor activity in real time. It displays a listing of the most CPU-intensive tasks on the system, and can provide an interactive inter face for manipulating processes. (q is to quit) 58. Q. How can you find configuration on linux? A. by using /sin/ifconfig If no arguments are given, ifconfig displays the status of the currently active interfaces. If a single interface argument is given, it displays the status of the given interface only; if a single -a argument is given, it displays the status of all interfaces, even those that are down. Otherwise, it configures an interface. 59. Q. How to find difference in two configuration files on the same server? A. Use diff command that is compare files line by line diff -u /usr/home/my_project1/etc/ABC.conf /usr/home/my_project2/etc/ABC.conf 60. Q. What is the best way to see the end of a logfile.log file? A. Use tail command - output the last part of files tail -n file_name ( the last N lines, instead of the last 10 as default) 61. Q. Please write a loop for removing all files in the current directory that contains a word 'log' A. for i in *log*; do rm $i; done 62. Question: How to switch to a previously used directory? Answer: cd -

1.

Q.How many VI editor modes do you know? A.Three modes Command mode: letters or sequence of letters interactively command vi. Insert mode: Text is inserted. Command line mode: enter this mode by typing ":" and entry command line the foot of the screen. 2. 3. Q. How can you terminate VI session? A. Use command: ZZ that is save changes and quit. Use command line: ":wq" that is write changes and quit. Use command line: ":q!" to ignore changes and quit.

at

Q. How can you copy lines into the buffer in command mode? A. yy - copy a single line defined by current cursor position 3yy - copy 3 lines. Current line and two lines below it.

You might also like