Você está na página 1de 17

How to print/display the first line of a file? There are many ways to do this.

However the easiest way to display the first line of a file is using the [head] command. $> head -1 file.txt No prize in guessing that if you specify [head -2] then it would print first 2 records of the file. Another way can be by using [sed] command. [Sed] is a very powerful text editor which can be used for various text manipulation purposes like this. $> sed '2,$ d' file.txt You may be wondering how does the above command work? OK, the 'd' parameter basically tells [sed] to delete all the records from display output from line no. 2 to last line of the file (last line is represented by $ symbol). Of course it does not actually delete those lines from the file, it just does not display those lines in standard output screen. So you only see the remaining line which is the first line. How to print/display the last line of a file? The easiest way is to use the [tail] command. $> tail -1 file.txt If you want to do it using [sed] command, here is what you should write: $> sed -n '$ p' test From our previous answer, we already know that '$' stands for the last line of the file. So '$ p' basically prints (p for print) the last line in standard output screen. '-n' switch takes [sed] to silent mode so that [sed] does not print anything else in the output. How to display n-th line of a file? The easiest way to do it will be by using [sed] I guess. Based on what we already know about [sed] from our previous examples, we can quickly deduce this command: $> sed n '<n> p' file.txt You need to replace <n> with the actual line number. So if you want to print the 4th line, the command will be $> sed n '4 p' test Of course you can do it by using [head] and [tail] command as well like below: $> head -<n> file.txt | tail -1

You need to replace <n> with the actual line number. So if you want to print the 4th line, the command will be $> head -4 file.txt | tail -1 How to remove the first line / header from a file? We already know how [sed] can be used to delete a certain line from the output by using the'd' switch. So if we want to delete the first line the command should be: $> sed '1 d' file.txt But the issue with the above command is, it just prints out all the lines except the first line of the file on the standard output. It does not really change the file inplace. So if you want to delete the first line from the file itself, you have two options. Either you can redirect the output of the file to some other file and then rename it back to original file like below: $> sed '1 d' file.txt > new_file.txt $> mv new_file.txt file.txt Or, you can use an inbuilt [sed] switch 'i' which changes the file in-place. See below: $> sed i '1 d' file.txt How to remove the last line/ trailer from a file in Unix script? Always remember that [sed] switch '$' refers to the last line. So using this knowledge we can deduce the below command: $> sed i '$ d' file.txt How to remove certain lines from a file in Unix? If you want to remove line <m> to line <n> from a given file, you can accomplish the task in the similar method shown above. Here is an example: $> sed i '5,7 d' file.txt The above command will delete line 5 to line 7 from the file file.txt How to remove the last n-th line from a file? This is bit tricky. Suppose your file contains 100 lines and you want to remove the last 5 lines. Now if you know how many lines are there in the file, then you can simply use the above shown method and can remove all the lines from 96 to 100 like below: $> sed i '96,100 d' file.txt file.txt] # alternative to command [head -95

But not always you will know the number of lines present in the file (the file may be generated dynamically, etc.) In that case there are many different ways to solve the problem. There are some ways which are quite complex and fancy. But let's first do it in a way that we can understand easily and remember easily. Here is how it goes: $> tt=`wc -l file.txt | cut -f1 -d' '`;sed i "`expr $tt - 4`,$tt d" test As you can see there are two commands. The first one (before the semi-colon) calculates the total number of lines present in the file and stores it in a variable called tt. The second command (after the semi-colon), uses the variable and works in the exact way as shows in the previous example.

How to check the length of any line in a file? We already know how to print one line from a file which is this: $> sed n '<n> p' file.txt Where <n> is to be replaced by the actual line number that you want to print. Now once you know it, it is easy to print out the length of this line by using [wc] command with '-c' switch. $> sed n '35 p' file.txt | wc c The above command will print the length of 35th line in the file.txt. How to get the nth word of a line in Unix? Assuming the words in the line are separated by space, we can use the [cut] command. [cut] is a very powerful and useful command and it's real easy. All you have to do to get the n-th word from the line is issue the following command: cut f<n> -d' ' '-d' switch tells [cut] about what is the delimiter (or separator) in the file, which is space ' ' in this case. If the separator was comma, we could have written -d',' then. So, suppose I want find the 4th word from the below string: A quick brown fox jumped over the lazy cat, we will do something like this: $> echo A quick brown fox jumped over the lazy cat | cut f4 d' ' And it will print fox How to reverse a string in unix? Pretty easy. Use the [rev] command. $> echo "unix" | rev xinu How to get the last word from a line in Unix file? We will make use of two commands that we learnt above to solve this. The commands are [rev] and [cut]. Here we go.

Let's imagine the line is: C for Cat. We need Cat. First we reverse the line. We get taC rof C. Then we cut the first word, we get 'taC'. And then we reverse it again. $>echo "C for Cat" | rev | cut -f1 -d' ' | rev Cat How to get the n-th field from a Unix command output? We know we can do it by [cut]. Like below command extracts the first field from the output of [wc c] command $>wc -c file.txt | cut -d' ' -f1 109 But I want to introduce one more command to do this here. That is by using [awk] command. [awk] is a very powerful command for text pattern scanning and processing. Here we will see how may we use of [awk] to extract the first field (or first column) from the output of another command. Like above suppose I want to print the first column of the [wc c] output. Here is how it goes like this: $>wc -c file.txt | awk ' ''{print $1}' 109 The basic syntax of [awk] is like this: awk 'pattern space''{action space}' The pattern space can be left blank or omitted, like below: $>wc -c file.txt | awk '{print $1}' 109 In the action space, we have asked [awk] to take the action of printing the first column ($1). More on [awk] later. How to replace the n-th line in a file with a new line in Unix? This can be done in two steps. The first step is to remove the n-th line. And the second step is to insert a new line in n-th line position. Here we go. Step 1: remove the n-th line $>sed -i'' '10 d' file.txt # d stands for delete

Step 2: insert a new line at n-th line position $>sed -i'' '10 i This is the new line' file.txt insert How to show the non-printable characters in a file? Open the file in VI editor. Go to VI command mode by pressing [Escape] and then [:]. Then type [set list]. This will show you all the non-printable characters, e.g. CtrlM characters (^M) etc., in the file. # i stands for

How to zip a file in Linux? Use inbuilt [zip] command in Linux How to unzip a file in Linux? Use inbuilt [unzip] command in Linux. $> unzip j file.zip How to test if a zip file is corrupted in Linux? Use -t switch with the inbuilt [unzip] command $> unzip t file.zip How to check if a file is zipped in Unix? In order to know the file type of a particular file use the [file] command like below: $> file file.txt file.txt: ASCII text If you want to know the technical MIME type of the file, use -i switch. $>file -i file.txt file.txt: text/plain; charset=us-ascii If the file is zipped, following will be the result $> file i file.zip file.zip: application/x-zip How to connect to Oracle database from within shell script? You will be using the same [sqlplus] command to connect to database that you use normally even outside the shell script. To understand this, let's take an example. In this example, we will connect to database, fire a query and get the output printed from the unix shell. Ok? Here we go $>res=`sqlplus -s username/password@database_name <<EOF SET HEAD OFF; select count(*) from dual; EXIT; EOF` $> echo $res 1

If you connect to database in this method, the advantage is, you will be able to pass Unix side shell variables value to the database. See below example

$>res=`sqlplus -s username/password@database_name SET HEAD OFF;

<<EOF

select count(*) from student_table t where t.last_name=$1; EXIT; EOF` $> echo $res 12 How to execute a database stored procedure from Shell script? $> SqlReturnMsg=`sqlplus -s username/password@database<<EOF BEGIN Proc_Your_Procedure( your-input-parameters ); END; / EXIT; EOF` $> echo $SqlReturnMsg How to check the command line arguments in a UNIX command in Shell Script? In a bash shell, you can access the command line arguments using $0, $1, $2, variables, where $0 prints the command name, $1 prints the first input parameter of the command, $2 the second input parameter of the command and so on. How to fail a shell script programmatically? Just put an [exit] command in the shell script with return value other than 0. this is because the exit codes of successful Unix programs is zero. So, suppose if you write exit -1 inside your program, then your program will thrown an error and exit immediately. How to list down file/folder lists alphabetically? Normally [ls lt] command lists down file/folder list sorted by modified time. If you want to list then alphabetically, then you should simply specify: [ls l] How to check if the last command was successful in Unix? To check the status of last executed command in UNIX, you can check the value of an inbuilt bash variable [$?]. See the below example: $> echo $? How to check if a file is present in a particular directory in Unix? Using command, we can do it in many ways. Based on what we have learnt so far, we can make use of [ls] and [$?] command to do this. See below:

$> ls l file.txt; echo $? If the file exists, the [ls] command will be successful. Hence [echo $?] will print 0. If the file does not exist, then [ls] command will fail and hence [echo $?] will print 1. How to check all the running processes in Unix? The standard command to see this is [ps]. But [ps] only shows you the snapshot of the processes at that instance. If you need to monitor the processes for a certain period of time and need to refresh the results in each interval, consider using the [top] command. $> ps ef If you wish to see the % of memory usage and CPU usage, then consider the below switches $> ps aux If you wish to use this command inside some shell script, or if you want to customize the output of [ps] command, you may use -o switch like below. By using -o switch, you can specify the columns that you want [ps] to print out. $>ps -e -o stime,user,pid,args,%mem,%cpu How to tell if my process is running in Unix? You can list down all the running processes using [ps] command. Then you can grep your user name or process name to see if the process is running. See below: $>ps -e -o stime,user,pid,args,%mem,%cpu | grep "opera" 14:53 opera 29904 sleep 60 14:54 opera 31536 ps -e -o stime,user,pid,arg 14:54 opera 31538 grep opera 0.0 0.0 0.0 0.0

0.0

0.0

How to get the CPU and Memory details in Linux server? In Linux based systems, you can easily access the CPU and memory details from the /proc/cpuinfo and /proc/meminfo, like this: $>cat /proc/meminfo $>cat /proc/cpuinfo

IMP:- UNIX PASSING MARKS:= 60% OF(LFH UNIX TEST+UNIX PRACTICAL ASSESSMENT)

TIME:1HOUR (dont rememberd the exact question,but question pattern will be similar to dis.....) There were two section of question u hav 2 create two files named <Emp ID>answer1.txt & <Emp ID>answer2.txt section 1 questions should be saved in <Emp ID>answer1.txt and section2 in <Emp ID>answer2.txt.

CREATE A FILE EMP.DAT HAVING CONTENTS:emp_id,emp_name,post,dept,doj,salary 1122,saxena,gm,account ,12-dec-52,6000 2233,gupta,dgm,sales,31-dec-40,9000 4545,agarwal,director,account ,06-july47,7500 5656,choudhury,executive,marketing,07-sep-50,5000 1265,singhvi,gm,admin ,12-sep-63,6000 0110,saksena,chairman ,marketing,12-nov-43,8000 5566,sharma,director,account ,23-aug-89,7000 7733,jayant,dgm,sales,29-may-70,6000 [imp:headings are not stored in file] SECTION 1 1> display the last two records 2>display the name of the employee having highest salary 3>sort the file according to month wise of doj field in ascending order 4>save the details of employee having highest salary in FILE1.DAT 5>display the employee names with line numbers 6>store the details of employee who is a director in FILE2.DAT SECTION 2 1>DISPALY THE UNIVERSAL TIME OF SYSTEM 2>DISPLAY CALENDAR OF PREVIOUS,CURRENT,NEXT MONTH AS OUTPUT 3>DISPLAY NAME,TIME,LINE,COMMMENT AS HEADING FOR THE OUTPUT OBTAINED BY WHO COMMAND 4>USE THE TAR ZIP UTILITY TO ZIP ALL .DAT FILES TO .TAR FILE 5>DISPLAY THE TOTAL SIZE(IN BLOCKS) OF FILES/DIR ON CONSOLE -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

FEW ADDITIONAL QUESTION FOR PRACTICE:1>DISPLAY the employee name having salary more than 8000 or to find the details of all those whose salary lies in between a particular range(use egrep) 2>display emp_id having salary not equal to 8000 3>total number of process running by a particular user 4>total logged in users 5>display all active processes 6>display all running processes 7>DISPLAY TOTAL NO. OF PROCESSES EXECUTED BY A PARTICULAR USER

for practice: do learn some basic command in details : date,cut,fgrep,grep,egrep,who,cal,sort,ps

Unix sample questions

LEVEL - I List all the files and subdirectories of the directory /bin = cd bin ls bin List all the files including hidden files in your current directory = ls -a List all the files starting with letter 'r' in your current directory = ls r* List all the files having three characters in their names from your current directory. = ls ??? List all the files with extension .doc in your current directory = ls *.doc List all the files having the first letter of their name within the range 'l' to , 's' from your current directory = ls [l-s]* Create a file text1 and read its input from keyboard = cat > text1 Copy contents of file text1 to another file text2 = cp text1 text2 Append the contents of file text2 to file text1 = cat >> text1 text2 Count the number of files in the current directory = ls|wc -w Display the output of command ls -l to a file and on the output screen = ls -l|cat > text3 or ls l|cat>>text2 From file text1 print all lines starting from 10th line = tail +10 text1 Find the number of users currently logged on to the system = who|wc -l Delete all the files with their names starting with "tmp" = rm tmp* LEVEL - II

1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.

1. Create a file FILE2 with some text in it. Increase the no. of hard links to the file FILE2 to 3 and check the inode number and link count for those names = ls -l FILE2 Fl1 Fl2|cut -d " " -f3,10 2. Using one single command, display the output of "who" and "pwd" commands =who;pwd 3. Display today's date = echo "Today is $(date+%a) $(date+%d) $(date+%h) $ (date+%y) " 4. Display the text message on monitor screen "We are done!!!" = echo "We are done!!!" 5. Display the message on monitor screen "The long listing of my home dir ----- is -----" = 'the long listing of my home dir '; pwd; echo ' is ';ls -l

LEVEL - III

1. List only the directories in your current directory = find -type d|nl 2. Display the name and count of the directories in the current directory = find -type d -print; find -type d|wc -l 3. Find out whether the users with a pattern "itp9" in their names have logged in =who|cut -d " " f1|fgrep itp9 4. Find out whether a particular user "itp9" has logged in n=`who|cut -d " " -f1|fgrep ncs|wc-l` if test $n -ne 0 then echo -e "no" else echo -e "yes" fi 5. Assign a value "Black" to var1 and then display the following message on the terminal using this variable "Sirius Black is a true marauder." Set var1 Black echo "Sirius $var1 is a true marauder." 6. Create the file employee.txt having ":" separated fields. The fields of record are : enumber, ename, eposition, esal, edoj, edept. Now answer the following.

1. 2. 3. 4. 5.

List all the employees along with a row number = cat employee.txt|cut -d ":" -f2|nl Sort the files as per names = cat employee.txt|sort -t ":" +1 -2 List top three salaried employees = cat employee.txt|sort -r -t ":" +3 -4|head -3 Rmove duplicate record from the file = cat employee.txt|unique List dept. no along with no. of emplooyees working in each dept =cat employee.txt|cut -d ":" -f6, 1|unique 6. Sort the file in descending order of salary = cat employee.txt|sort -r -t ":" +3 -4

1) What is UNIX? It is a portable operating system that is designed for both efficient multi-tasking and multuser functions. Its portability allows it to run on different hardware platforms. It was written is C and lets user do processing and control under a shell. 2) What are filters? The term Filter is often used to refer to any program that can take input from standard input, perform some operation on that input, and write the results to standard output. A Filter is also any program that can be used between two other programs in a pipeline. 3) What is a typical syntax being followed when issuing commands in shell? Typical command syntax under the UNIX shell follows the format: Command [-argument] [-argument] [--argument] [file] 4) Is there a way to erase all files in the current directory, including all its sub-directories, using only one command? Yes, that is possible. Use rm r * for this purpose. The rm command is for deleting files. The r option will erase directories and subdirectories, including files within. The asterisk represents all entries. 5) What is the chief difference between the v and x option s to set? The v option echoes each command before arguments and variables have been substituted for; the x option echoes the commands after substitution has taken place. 6) What is Kernel? Kernel is the UNIX operating system. It is the master program that controls the computers resources, allotting them to different users and to different tasks. However, the kernel doesnt deal directly with a user. Instead, it starts up a separate, interactive program, called a shell, for each user when he/she logs on. 7) What is Shell? A shell acts as an interface between the user and the system. As a command interpreter, the shell takes commands and sets them up for execution. 8 ) What are the key features of the Korn Shell? - history mechanism with built-in editor that simulates emacs or vi - built-in integer arithmetic - string manipulation capabilities - command aliasing - arrays - job control 9) What are some common shells and what are their indicators? sh Bourne shell csh C SHell bash Bourne Again Shell tcsh enhanced C Shell zsh Z SHell ksh Korn SHell 10) Differentiate multiuser from multitask.

Multiuser means that more than one person can use the computer at the same time. Multitask means that even a single user can have the computer work on more than one task or program at the same time. 11) What is command substitution? Command substitution is one of the steps being performed every time commands are processed by the shell. Commands that are enclosed in backquotes are executed by the shell. This will then replace the standard output of the command and displayed on the command line. 12) What is a directory? Every file is assigned to a directory. A directory is a specialized form of file that maintains a list of all files in it. 13) What is inode? An inode is an entry created on a section of the disk set aside for a file system. The inode contains nearly all there is to know about a file, which includes the location on the disk where the file starts, the size of the file, when the file was last used, when the file was last changed, what the various read, write and execute permissions are, who owns the file, and other information. 14) You have a file called tonky in the directory honky. Later you add new material to tonky. What changes take place in the directory, inode, and file? The directory entry is unchanged, since the name and inode number remain unchanged. In the inode file, the file size, time of last access, and time of last modification are updated. In the file itself, the new material is added. 15) Describe file systems in UNIX Understanding file systems in UNIX has to do with knowing how files and inodes are stored on a system. What happens is that a disk or portion of a disk is set aside to store files and the inode entries. The entire functional unit is referred to as a file system. 16) Differentiate relative path from absolute path. Relative path refers to the path relative to the current path. Absolute path, on the other hand, refers to the exact path as referenced from the root directory. 17) Explain the importance of directories in a UNIX system Files in a directory can actually be a directory itself; it would be called a subdirectory of the original. This capability makes it possible to develop a tree-like structure of directories and files, which is crucial in maintaining an organizational scheme. 18) Briefly describe the Shells responsibilities - program execution - variable and file name substitution - I/O redirection - pipeline hookup - environment control - interpreted programming language 19) What are shell variables? Shell variables are a combination of a name ( identifier), and an assigned value, which exist within the shell. These variables may have default values, or whose values can be manually

set using the appropriate assignment command. Examples of shell variable are PATH, TERM and HOME. 20) What are the differences among a system call, a library function, and a UNIX command? A system call is part of the programming for the kernel. A library function is a program that is not part of the kernel but which is available to users of the system. UNIX commands, however, are stand-alone programs; they may incorporate both system calls and library functions in their programming. 21) What is Bash Shell? It is a free shell designed to work on the UNIX system. Being the default shell for most UNIXbased systems, it combines features that are available both in the C and Korn Shell. 22) Enumerate some of the most commonly used network commands in UNIX - telnet used for remote login - ping an echo request for testing connectivity - su user switching command - ftp file transfer protocol used for copying files - finger information gathering command 23) Differentiate cmp command from diff command. The cmp command is used mainly to compare two files byte by byte, after which the first encountered mismatch is shown. On the other hand, the diff command is used to indicate the changes that is to be made in order to make the two files identical to each other. 24) What is the use of -l when listing a directory? -l, which is normally used in listing command like ls, is used to show files in a long format, one file per line. Long format refers to additional information that is associated with the file, such as ownership, permissions, data and filesize. 25) What is piping? Piping, represented by the pipe character |, is used to combine two or more commands together. The output of the first command serves as input the next command, and so on. 26) What is a superuser? A superuser is a special type user who has open access to all files and commands on a system. Note that the superusers login is usually root, and is protected by a so-called root password. 27) How do you determine and set the path in UNIX? Each time you enter a command, a variable named PATH or path will define in which directory the shell will search for that command. In cases wherein an error message was returned, the reason maybe that the command was not in your path, or that the command itself does not exist. You can also manually set the path using the set path = [directory path] command. 28) Is it possible to see information about a process while it is being executed? Every process is uniquely identified by a process identifier. It is possible to view details and status regarding a process by using the ps command. 29) What is the standard convention being followed when naming files in UNIX? One important rule when naming files is that characters that have special meaning are not allowed, such as * / & and %. A directory, being a special type of file, follows the same

naming convention as that of files. Letters and numbers are used, along with characters like underscore and dot characters. 30) Why is it that it is not advisable to use root as the default login? The root account is very important, and with abusive usage, can easily lead to system damage. Thats because safeguards that normally apply to user accounts are not applicable to the root account. 31) What is the use of the tee command? The tee command does two things: one is to get data from the standard input and send it to standard output; the second is that it redirects a copy of that input data into a file that was specified. 32) Differentiate cat command from more command. When using the cat command to display file contents, large data that does not fit on the screen would scroll off without pausing, therefore making it difficult to view. On the other hand, using the more command is more appropriate in such cases because it will display file contents one screen page at a time. 33) What is parsing? Parsing is the process of breaking up of a command line into words. This is made possible by using delimiters and spaces. In the event that tabs or multiple spaces are part of the command, these are eventually replaced by a single space. 34) What is pid? Pid is short for Process ID. It is used primarily to identify every process that runs on the UNIX system, whether it runs on the foreground or runs at the background. Every pid is considered unique. 35) How does the system know where one command ends and another begins? Normally, the newline character, which is generated by the ENTER or RETURN key, acts as the signpost. However, the semicolon and the ampersand characters can also serve as command terminators. 37) What is wild-card interpretation? When a command line contains wild-card characters such as * or ?, these are replaced by the shell with a sorted list of files whose pattern matches the input command. Wild-card characters are used to setup a list of files for processing, instead of having it specified one at a time. 38) What is the output of this command? $who | sort logfile > newfile In this command, the output from the command who becomes the input to the sort command. At the same time, sort opens logfile, arranges it together with the output from the command who, and places the final sorted output to the file newfile. 39) How do you switch from any user type to a super user type? In order to switch from any user type to a superuser, you use the su command. However, you will be asked to key in the correct superuser password before full access privileges are granted to you. 40) What would be the effect of changing the value of PATH to: .:/usr/della/bin: /bin: /usr/bin This would cause the shell to look in the /usr/della/bin directory after looking in the current directory and before looking in the /bin directory when searching for a command file.

41) Write a command that will display files in the current directory, in a colored, long format. Answer: ls -l color 42) Write a command that will find all text files in a directory such that it does not contain the word amazing in any form (that is, it must include the words Amazing, AMAZING, or aMAZINg) Answer: grep vi amazing *.txt 43) Write a command that will output the sorted contents of a file named IN.TXT and place the output in another file named OUT.TXT, while at the same time excluding duplicate entries. Answer: sort IN.TXT | uniq > OUT.TXT 44) Write a command that will allow a UNIX system to shut down in 15 minutes, after which it will perform a reboot. Answer: /sbin/shutdown r +10 45) What command will change your prompt to MYPROMPT: ? To change a prompt, we use the PS1 command, such as this: PS1 = MYPROMPT: 46) What does this command do? cat food 1 > kitty Answer: it redirects the output of cat food into the file kitty; the command is the same as: cat food > kitty 47) What is wrong with this interactive shell script? echo What month is this? read $month echo $month is as good a month as any. Answer: Initially, the question mark should be escaped (\?) so that it is not interpreted as a shell metacharacter. Second, it should be read month, not read $month. 48) Write a shell script that requests the users age and then echoes it, along with some suitable comment. Answer: echo Hello! What\s your age\? read age echo $age! I\ll be obsolete by that age! 49) Write a script that prints out date information in this order: time, day of week, day number, month, year (sample output: 17:34:51 PDT Sun 12 Feb 2012) Answer: set date echo $4 $5 $1 $3 $2 $6 50) Write a script that will show the following as output: Give me a U! U! Give ma a N! N! Give me a I! I!

Give me a X! X! Answer: for i in U N I X do echo Give me a $i! echo $i! done

1. What is UNIX? It is a portable operating system that is designed for both efficient multi-tasking and mult-user functions. Its portability allows it to run on different hardware platforms. It was written is C and lets user do processing and control under a shell. 2. What is Shell? A shell acts as an interface between the user and the system. As a command interpreter, the shell takes commands and sets them up for execution. 3. What are the key features of the Korn Shell? - history mechanism with built-in editor that simulates emacs or vi - built-in integer arithmetic - string manipulation capabilities - command aliasing - arrays - job control 4. What are some common shells and what are their indicators? sh Bourne shell csh C SHell bash Bourne Again Shell tcsh enhanced C Shell zsh Z SHell ksh Korn SHell 5. What is shell scripting in UNIX? Shell scripting is used to program command line of an operating system. Shell Scripting is also used to program the shell which is the base for any operating system. Shell scripts often refer to programming UNIX. Shell scripting is mostly used to program operating systems of windows, UNIX, Apple etc. Also this script is used by companies to develop their own operating system with their own features. 6. What is a typical syntax being followed when issuing commands in shell? Typical command syntax under the UNIX shell follows the format: Command [-argument] [-argument] [--argument] [file] 7. What is command substitution? Command substitution is one of the steps being performed every time commands are processed by the shell. Commands that are enclosed in backquotes are executed by the shell. This will then replace the standard output of the command and displayed on the command line.

8. What is a directory? Every file is assigned to a directory. A directory is a specialized form of file that maintains a list of all files in it. 9. What is history command in UNIX? We use history command along with grep command in unix to find any relevant command you have already executed. 10. How do you copy file from one host to other? By using "scp" command. You can also use rsync command to answer this UNIX interview question or even sftp would be ok. 11. How do you find which process is taking how much CPU? By using "top" command in UNIX. 12. How do you check how much space left in current drive? By using "df" command in UNIX. For example "df -h ." will list how full your current drive is. 13. How do you know if a remote host is alive or not? You can check these by using either ping or telnet command in UNIX. 14. How will you run a process in background? How will you bring that into foreground and how will you kill that process? For running a process in background use "&" in command line. For bringing it back in foreground use command "fg jobid" and for getting job id you use command "jobs", for killing that process find PID and use kill -9 PID command. 15. How will you find which operating system your system is running on in UNIX? By using command "uname -a" in UNIX 16. What is the command to list all the links from a directory? You can answer command like: ls -lrt | grep "^l" 17. How will you create a read-only file in your home directory? You need to create a file and change its parameter to read-only by using chmod command you can also change your umask to create read only file. touch file chmod 400 file 18. What is the difference between Swapping and Paging? Swapping:Whole process is moved from the swap device to the main memory for execution. Process size must be less than or equal to the available main memory. It is easier to implementation and overhead to the system. Swapping systems does not handle the memory more flexibly as compared to the paging systems. Paging:Only the required memory pages are moved to main memory from the swap device for execution. Process size does not matter. Gives the concept of the virtual memory. It provides greater flexibility in mapping the virtual address space into the physical memory of the machine. Allows more number of processes to fit in the main memory simultaneously. Allows the greater process size than the available physical memory. Demand paging systems handle the memory more flexibly.

19. What are filters? The term Filter is often used to refer to any program that can take input from standard input, perform some operation on that input, and write the results to standard output. A Filter is also any program that can be used between two other programs in a pipeline. 20. Differentiate multiuser from multitask. Multiuser means that more than one person can use the computer at the same time. Multitask means that even a single user can have the computer work on more than one task or program at the same time. 21. What is inode? An inode is an entry created on a section of the disk set aside for a file system. The inode contains nearly all there is to know about a file, which includes the location on the disk where the file starts, the size of the file, when the file was last used, when the file was last changed, what the various read, write and execute permissions are, who owns the file, and other information

Você também pode gostar