You are on page 1of 7

1.

What is the command for " how many shell is running in your system or how many shell supported by your system " ?. how many shell supported by your system check the file /etc/shells 2.How to rename all the files in a folder having specific extension? Example: I have some files with extension (.txt) in a folder name 'Test'. I have to rename all the .txt files in a test and its subdirectories to .my extension. for file in `ls` ; do NEW=`echo $file | sed 's/.txt/.my/g'` ; mv $file $NEW ; done 3. how did u debugging in unix/ linux platform ??( project Related) If it is a shell script use #!/bin/ksh -x 4.Why we are writting shell scripts? Plz if possible explain it briefly. 1.Interactive mood:-As Shell scripting is working like as interpreter (not likely compiler) in a int eractive mood. 2. Less time:-it will take less time than C or C++ or other file to process 5. what do u mean by $#,$* in unix programming? $# The number of command line argument 6. Hi, i want to zip the files that generates automatically every few minutes (f iles generated are in .arc extension)....any body write a script for this... tha nks in advance while true do find . -name *.arc -exec gzip {} \; sleep 300 done 7.What is the use of "test" command? "Test" command checks file and directory types and checks value. EX: create a empty file test (touch test) if test -f test then echo "File is nonempty" else echo "file is empty" fi There are different options like -d -b -e.You can explore all. 8. How to declare functions in unix shell script? First method:

function function_name { } Second Method: function_name() { } For both methods, the invocation of function would be in the same format only. Invocation: function_name $* All the arguments on the command line. 9.: How to include comments in your shell scripts? # comments 10.What is "test"? How it is used in shell scripting? test is used to validate an expression in shell script. for ex:in if loop ,is used as follows if test a > b { #some statements } fi instead of if [ a > b ] { #some statements } fi 11.what is "umask"? umask is to set the default directory and file access restriction set during it creation. For Example if Umask is 033( means 000011011 ) then directory permission will be its complement so default dir permission is 111100100 ( means 744) now,AND dir permission with 110110110 (666) so it comes to and file permission i s 110100100 (644) 12. When we login into our account which files are executed? .profile .login 13. How to make userdefined variables to available for all other shells? By exporting the variable export VAR=value_of_the_variable

14. How to create environment variables?What are the conditions for creating var iables? We can create environment variable by using export command.(Also by using set, b ut difference between set and export is the which has been exported is being availabe in cloned/child shell.) export VAR="Welcome" But problem is this variable has life span of sesson only. For making it permana net we need to put that in login script. 15.How to change our default shell? Normally the diffault shell can not be changed by user in Solaris system. Becaus e chsh command is not available in Solaris environment. But one can change the default shell in Linux environment b y using following command. chsh -s /bin/ksh After issuing this command it will ask for passeord and if password is given suc cessfully then default shell will be 16.What is Path variable?What is its use? PATH is an environment variable.It contains the sequence of paths seperated by c olons(:) when we enter commands on the prompt the shell first checks that coorre sponding program to execute in those paths specified in PATH variable. We can print that sequnece by typing echo $PATH changed. Here you have to give t he full path of shell. 17.How to modify the PATH variable and make it executable? we can set PATH by using export PATH command. ex:PATH=/opt/j2sdk1.4.2_04/bin:............ export PATH and to make it executable we can set the same in ".bash_profile". 18. What is the difference between a variable and value? variable may be change but value still constant. 19.How would you print just the 25th line in a file using smallest shell script? head -25 filename | tail -1 20. How would you replace the n character in a file with some xyz? sed -i 's/n/xyz/g' filename 21.What does $# stand for? No of arguments passed to script . 22. If you have a string "one two three", which shell command would you use to e xtract the strings? Below methods will work. You could use either cut or awk

echo "read data" read data echo $data | cut -f1 -d" " echo $data | cut -f2 -d" " echo $data | cut -f3 -d" " echo $data |awk -F" " '{print $1}' echo $data |awk -F" " '{print $2}' echo $data |awk -F" " '{print $3} 23.What is the difference between a shell variable that is exported and the one that is not exported? the major difference between the shell variable that is exported and not is vari able exported using export command is global to all shell,where as the other shell variables are local to their res pective shells. 24.How will you list only the empty lines in a file (using grep)? grep "^$" filename 25.What are the Different types of shells? sh - bourne shell ksh - korn shell csh - c shell bash - bourne again shell in linux 26.What is the basic difference you find between a shell script and perl? Shell script is platform(OS) only for Unix flavour,dependent whereas perl is OS independent 27.what is the difference between writing code in shell and editor? If we write code in shell it is called we are using the shell as interractive mo de.It is inconvenient to write complex code(means entering complex or compound c ommands to execute by seperating with ";" semicolon) For our convenient and also to frame a new functionality by using different comm ands we use non interactive mode of shell that is we type code in a editor and we execute that. 28. What is use of "cut" command? cut is used to get a specific data from a file. Supppose you want to get a data in a file from column 10 to 20, you can get it by using cut eg: cat filename.txt | cut -c 10-20 eg: cut -c10-20 <filename.txt> 29. What are the three main forms of enabling debugging in a shell script? set -x set -v set -n

30.What is the difference between a 'thread' and a 'process'? Process is a program in execution whereas thread is a separate path of execution in a program. Process & Thread share almost all datastructure except (thread has it's own register & stack area ). Process is a program under execution,but thread is a light weight process whi ch has seperate way of execution.Threads are part of process.Single process can contain number of threads at a time. A process is a collection of virtual memory space, code, data, and system resour ces. All thread with in a process share process instruction,code & data segment,open file descriptor,signal handler,userID and GroupID. Thread has its own set of register including program counter,stack pointer 31.what is the difference between cmp and diff commands cmp - It will compare files byte by byte Ex: cmp text text1 text text1 differ: byte 2, line 1 diff - It will compare files line by line If there are any differences in the fi le. Then it will print to stdout along with all lines. 32.How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" $line = "hi Praveen How are you"; $line =~ s/\b(\w+)\b/ucfirst($1)/e; 33.how to read systems current date and time echo "the current date and time is:" echo `date` 34.How do you rename the files(*.sh) with file names containing space in it?for example "interview question.sh" needs to rename to "interview-question.sh". For single file, you can do following command; mv interview\ question.sh interview-question.sh For multiple files on the current working folder; for i in *\ *.sh do j=`echo $i|sed "s/ /-/g"` mv "$i" $j done 35. How do you schedule a command to run at 4:00 every morning? Step 1. Step 2. Step 3. 0 4 * * Set environemen variable EDITOR=vi if not set Give command crontab -e Add following entry at the end * <Your command to run at 4:00 am morning>

1. There are two ways to schedule a script to run exactly at 4:00 AM every morni ng a: CRONTAB b. AT (at command executes only once) Crontab format * * * * * <command> <minute> <hour> <date> <month> <day_of_the_week> command <0-59> <0-23> <1-31> <1-12> <07> command 36.how to search for vowels a,e,i,o,u appearing in the same sequence in a file grep -w "a[^aiou]*e[^aeou]*i[^aeiu]*o[^aeio]*u" filename 37. how to separate the even and odd number generated from one file to two separ ate file i.e. even numbers in file1.txt and odd numbers in file2.txt echo enter filename read file for n in `cat $file` do i=`expr $n % 2` if [ $i -eq 0 ] then echo $n>>even.txt else echo $n>>odd.txt fi done 38.what does "kill -9" and "kill -1" do Kill -9 ===> send sure kill signal to process..but, remember it can't kill all processes eg: init process run : kill -9 1 [it can't effect] Kill -1 ===> send signal hangup to process.. 39.what is the meaning of First line of shell script ,what is meaning of #! plea s explain brifly #! indicates from where the path of the interpretor should be considered and als o directs that the contents of the file which will be following will be executed under the guidelines of this inte rpretor being used. 40.Where cron file kept? It is in /var/spool/cron/crontabs Each user have seperate file in this location. moreover normal user cannot view this file, only root user can access. 41.write a shell script that counts a number of unique word contained in the fil e and print them in alphabetical order line by line?

cat filename | uniq -u | sort -n print $line;

You might also like