You are on page 1of 7

RE: What does $? return? -------------------------------------------------------------------------------$? will return exit status of command .

0 if command gets successfully executed , non-zero if command failed. RE: How would you print just the 25th line in a file (... -------------------------------------------------------------------------------head -25 filename|tail -1OR RE: How would you print just the 25th line in a file (... -------------------------------------------------------------------------------cat -n filename | grep '25' RE: How would you get the character positions 10-20 from a text file? -------------------------------------------------------------------------------cat filename.txt | cut -c 10-20 RE: When you login to a c shell, which script would be run first? (before the t erminal is ready for the -------------------------------------------------------------------------------.profile file will execute first when a user logs in. RE: How do you read arguments in a shell program - $1,... -------------------------------------------------------------------------------by using : exec<$1 or exec<$2

RE: What are the different kinds of loops available in shell script? -------------------------------------------------------------------------------Broadly categorised in 3 for while until RE: How do you schedule a command to run at 4:00 every morning? -------------------------------------------------------------------------------do first crontab -e and then add a line like below 0 4 * * * name of the command RE: How will you list only the empty lines in a file (using grep)? -------------------------------------------------------------------------------grep "^$" filename.txt

RE: What is the difference between a shell variable th... -------------------------------------------------------------------------------exported variable is visible to the child processes while the normal variables are not. try this simple script it will clear your concept :script a.sh :---------export A=3 B=5 sh b.sh -------script b.sh :----------echo "exported variable $A is :- $A" echo "Variable $B -- $B " --------A persists in b.sh whereas B doesn't. RE: What does $# stand for? -------------------------------------------------------------------------------$# will return the number of parameters that are passed as the command-line argu ments RE: Different types of shells? -------------------------------------------------------------------------------The Bourne shell (sh) , The C shell (csh) , The Korn shell (ksh) , The Z-Shell (zsh) , The POSIX shell, The Bourne Again SHell (Bash)null RE: What is the difference between a 'thread' and a 'p... -------------------------------------------------------------------------------Thread is the part of the process when we execute a programm and the process is created when execute a program. RE: Explain the working of Virtual Memory? -------------------------------------------------------------------------------It is capacity of hard disk which is used by RAM for paging. RE: write a shell script to identify the given string ... --------------------------------------------------------------------------------

print("Please enter a string "); $input_string = <STDIN>; chop($input_string); $rev_string = reverse($input_string); if($input_string eq $rev_string){ print("The string is a palindrome"); }else{ print("The string is NOT a palindrome"); } RE: How Connect to a Database in Shell Programming?Ple... -------------------------------------------------------------------------------Hi all, By using shell script, #!user/bin/bash sqlplus ' / as sysdba ' >>EOF startup shutdown immediate >>EOF RE: what is this line in the shell script do ???... -------------------------------------------------------------------------------This line is called as "Hash Bang" Statement. This tells the OS that the particu lar needs the respective shell for execution. If a script file has this hash ban g statement along with execution permission, then this file can be run directly without invoking thru shell command.Ex:$ instead of$ksh RE: What is use of "cut" command ?Give some examples. ... -------------------------------------------------------------------------------1. CUT is used to get the specific portion(column) of information from a files s eparated by a specific charecter(ex: CSV file) ex: more /etc/passwd|cut -d":" -f1 The above command is used to list the user accounts on the server. 2. AWK ex: ls -al|awk '{print $9}' The above command is used to get the list of filenames in the current directory. Here the fields are need not be seperated by a specific charecter. 3. SED is similar to GREP command. RE: How to find/see the file which is created today,s ... -------------------------------------------------------------------------------Hi, find . -atime 0 -type f -exec ls -ltr {} ; | grep "`date +%b %d`"

This command will show the files which are created today. But for ur second part of the quesiton i needto analyse more, Explanation: find . -atime 0 -type f -exec ls -ltr {} This will list the files where are accessed and created today. grep "`date +%b %d`"

Re: how to delete all the files with extension .dat rom a directory tree from ro ot to third level in a single unix command? Answer # 1 1st find the .dat file and place in file example : find . -name *.date > temp then add rm infrent of paths in that file adn run the script. example : :%s/\.\//rm \.\// open temp file run above vi command and rm the script example : sh temp RE: How to extract the second row of a text-file? -------------------------------------------------------------------------------head -2 filename|tail -1 RE: how to delete a word from a file using shell scrip... -------------------------------------------------------------------------------sed -e 's/word//g' filename Extended grep is called as egrep. grep -E will do the same function as egrep Re: What is the use of "test" command? Answer # 1 "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. Re: Create a bash shell script that removes all files whose names end with a "~" from your home directory and subdirectories. Name this script "cleanup.sh" Answer # 1 #/bin/bash rm `find . -name *~`

List the files in current directory sorted by size ? - ls -l | grep ^- | sort -n r List the hidden files in current directory ? - ls -a1 | grep "^\." Delete blank lines in a file ? - cat sample.txt | grep -v ^$ > new_sample.txt Search for a sample string in particular files ? - grep .Debug. *.confHere grep uses the string .Debug. to search in all files with extension..conf. under curre nt directory. Display the last newly appending lines of a file during appendingdata to the sam e file by some processes ? - tail .f Debug.logHere tail shows the newly appended data into Debug.log by some processes/user. Display the Disk Usage of file sizes under each directory in currentDirectory ? - du -k * | sort .nr (or) du .k . | sort -nr Change to a directory, which is having very long name ? - cd CDMA_3X_GEN*Here or iginal directory name is . .CDMA_3X_GENERATION_DATA.. Display the all files recursively with path under current directory ? - find . depth -print Set the Display automatically for the current new user ? - export DISPLAY=`eval w ho am i | cut -d"(" -f2 | cut -d")" -f1?`Here in above command, see single quote , double quote, grave ascent is used. Observe carefully. Display the processes, which are running under yourusername ? - ps .aef | grep M aheshvjHere, Maheshvj is the username. List some Hot Keys for bash shell ? - Ctrl+l . Clears the Screen. Ctrl+r . Does a search in previously given commands in shell. Ctrl+u - Clears the typing befor e the hotkey. Ctrl+a . Places cursor at the beginning of the command at shell. C trl+e . Places cursor at the end of the command at shell. Ctrl+d . Kills the she ll. Ctrl+z . Places the currently running process into background. Display the files in the directory by file size ? - ls .ltr | sort .nr .k 5 How to save man pages to a file ? - man <command> | col .b > <output-file>Exampl e : man top | col .b > top_help.txt How to know the date & time for . when script is executed ? - Add the following script line in shell script.eval echo "Script is executed at `date`" >> timeinfo .infHere, .timeinfo.inf. contains date & time details ie., when script is execut ed and history related to execution. How do you find out drive statistics ? - iostat -E Display disk usage in Kilobytes ? - du -k Display top ten largest files/directories ? - du -sk * | sort -nr | head How much space is used for users in kilobytes ? - quot -af How to create null file ? - cat /dev/null > filename1 Access common commands quicker ? - ps -ef | grep -i $@ Display the page size of memory ? - pagesize -a Display Ethernet Address arp table ? - arp -a Display the no.of active established connections to localhost ? - netstat -a | g rep EST Display the state of interfaces used for TCP/IP traffice ? - netstat -i Display the parent/child tree of a process ? - ptree <pid> Example: ptree 1267 Show the working directory of a process ? - pwdx <pid> Example: pwdx 1267 Display the processes current open files ? - pfiles <pid> Example: pfiles 1267

Display the inter-process communication facility status ? - ipcs Display the top most process utilizing most CPU ? - top .b 1 Alternative for top command ? - prstat -a How do you find out what s your shell? - echo $SHELL What s the command to find out today s date? - date What s the command to find out users on the system? - who How do you find out the current directory you re in? - pwd How do you remove a file? - rm How do you remove a - rm -rf How do you find out your own username? - whoami How do you send a mail message to somebody? - mail somebody@techinterviews.com s Your subject -c cc@techinterviews.com How do you count words, lines and characters in a file? - wc How do you search for a string inside a given file? - grep string filename How do you search for a string inside a directory? - grep string * How do you search for a string in a directory with the subdirectories recursed? - grep -r string * What are PIDs? - They are process IDs given to processes. A PID can vary from 0 to 65535. How do you list currently running process? - ps How do you stop a process? - kill pid How do you find out about all running processes? - ps -ag How do you stop all the processes, except the shell window? - kill 0 How do you fire a process in the background? - ./process-name & How do you refer to the arguments passed to a shell script? - $1, $2 and so on. $0 is your script name. What s the conditional statement in shell scripting? - if {condition} then fi How do you do number comparison in shell scripts? - -eq, -ne, -lt, -le, -gt, -ge How do you test for file properties in shell scripts? - -s filename tells you if the file is not empty, -f filename tells you whether the argument is a file, an d not a directory, -d filename tests if the argument is a directory, and not a f ile, -w filename tests for writeability, -r filename tests for readability, -x f ilename tests for executability How do you do Boolean logic operators in shell scripting? - ! tests for logical not, -a tests for logical and, and -o tests for logical or. How do you find out the number of arguments passed to the shell script? - $# What s a way to do multilevel if-else s in shell scripting? - if {condition} then {s tatement} elif {condition} {statement} fi How do you write a for loop in shell? - for {variable name} in {list} do {statem ent} done How do you write a while loop in shell? - while {condition} do {statement} done How does a case statement look in shell scripts? - case {variable} in {possiblevalue-1}) {statement};; {possible-value-2}) {statement};; esac How do you read keyboard input in shell scripts? - read {variable-name} How do you define a function in a shell script? - function-name() { #some code h ere return } How does getopts command work? - The parameters to your script can be passed as -n 15 -x 20. Inside the script, you can iterate through the getopts array as whi le getopts n:x option, and the variable $option contains the value of the entere d option. List the files in current directory sorted by size ? - ls -l | grep ^- | sort -n r List the hidden files in current directory ? - ls -a1 | grep "^\." Delete blank lines in a file ? - cat sample.txt | grep -v ^$ > new_sample.txt

Search for a sample string in particular files ? - grep Debug *.confHere grep uses the string Debug to search in all files with extension .conf under current directory . Display the last newly appending lines of a file during appendingdata to the sam e file by some processes ? - tail f Debug.logHere tail shows the newly appended d ata into Debug.log by some processes/user. Display the Disk Usage of file sizes under each directory in currentDirectory ? - du -k * | sort nr (or) du k . | sort -nr Change to a directory, which is having very long name ? - cd CDMA_3X_GEN*Here or iginal directory name is CDMA_3X_GENERATION_DATA . Display the all files recursively with path under current directory ? - find . depth -print Set the Display automatically for the current new user ? - export DISPLAY=`eval w ho am i | cut -d"(" -f2 | cut -d")" -f1?`Here in above command, see single quote , double quote, grave ascent is used. Observe carefully. Display the processes, which are running under yourusername ? - ps aef | grep Mah eshvjHere, Maheshvj is the username. List some Hot Keys for bash shell ? - Ctrl+l Clears the Screen. Ctrl+r Does a se arch in previously given commands in shell. Ctrl+u - Clears the typing before th e hotkey. Ctrl+a Places cursor at the beginning of the command at shell. Ctrl+e Places cursor at the end of the command at shell. Ctrl+d Kills the shell. Ctrl+z Places the currently running process into background. Display the files in the directory by file size ? - ls ltr | sort nr k 5 How to save man pages to a file ? - man <command> | col b > <output-file>Example : man top | col b > top_help.txt How to know the date & time for when script is executed ? - Add the following sc ript line in shell script.eval echo "Script is executed at `date`" >> timeinfo.i nfHere, timeinfo.inf contains date & time details ie., when script is executed and history related to execution. How do you find out drive statistics ? - iostat -E Display disk usage in Kilobytes ? - du -k Display top ten largest files/directories ? - du -sk * | sort -nr | head How much space is used for users in kilobytes ? - quot -af How to create null file ? - cat /dev/null > filename1 Access common commands quicker ? - ps -ef | grep -i $@ Display the page size of memory ? - pagesize -a Display Ethernet Address arp table ? - arp -a Display the no.of active established connections to localhost ? - netstat -a | g rep EST Display the state of interfaces used for TCP/IP traffice ? - netstat -i Display the parent/child tree of a process ? - ptree <pid> Example: ptree 1267 Show the working directory of a process ? - pwdx <pid> Example: pwdx 1267 Display the processes current open files ? - pfiles <pid> Example: pfiles 1267 Display the inter-process communication facility status ? - ipcs Display the top most process utilizing most CPU ? - top b 1 Alternative for top command ? - prstat -a

You might also like