unixfaq

download unixfaq

of 7

Transcript of unixfaq

  • 7/28/2019 unixfaq

    1/7

    Using the commands ps, cut, tr and kill, along with pipes, write a commandthat will find all sleep processes running on the system and kill them?

    Answer : ps: check process statusSyntax: ps ?optionOption:e: list all currently running processes (A for Linux)f: gives full listing (give ancestry for Linux)l: gives long listingu username: list processes for the user onlyS: sleepingO: runningR: on run queueZ: zombie (parent didn?t wait for death of its childT: stopped or suspended

    Question Rating View Answer

    Difference Between Grep and Find command ? View Answer

    Using the commands ps, cut, tr and kill, alongwith pipes, write a command that will find allsleep processes running on the system and killthem?

    View Answer

    What is the use of the command "ls -xchapter[1-5]"

    View Answer

    What is relative path and absolute path. View Answer

    Explain kill() and its possible return values.

    View Answer

    What is a pipe and give an example? View Answer

    How to terminate a process which is runningand the specialty on command kill 0? View Answer

    What is redirection?

    View Answer

    What are shell variables?

    View Answer

    How to switch to a super user status to gainprivileges?

    View Answer

    How does the kernel differentiate device filesand ordinary files?

    View Answer

    How many prompts are available in a UNIXsystem?

    View Answer

    Name the data structure used to maintain fileidentification?

    View Answer

    Is it possible to count number char, line in afile; if so, How?

    View Answer

    Is ?du? a command? If so, what is its use? View Answer

    What is the use of the command "ls -xchapter[1-5]"

    View Answer

    Is it possible to restrict incoming message? View Answer

    Is it possible to create new a file system inUNIX?

    View Answer

    http://www.coolinterview.com/interview/13987/http://www.coolinterview.com/interview/12729/http://www.coolinterview.com/interview/12729/http://www.coolinterview.com/interview/12729/http://www.coolinterview.com/interview/12729/http://www.coolinterview.com/interview/12729/http://www.coolinterview.com/interview/7472/http://www.coolinterview.com/interview/7472/http://www.coolinterview.com/interview/7472/http://www.coolinterview.com/interview/2505/http://www.coolinterview.com/interview/2505/http://www.coolinterview.com/interview/2505/http://www.coolinterview.com/interview/2504/http://www.coolinterview.com/interview/2504/http://www.coolinterview.com/interview/2503/http://www.coolinterview.com/interview/2503/http://www.coolinterview.com/interview/2503/http://www.coolinterview.com/interview/2502/http://www.coolinterview.com/interview/2502/http://www.coolinterview.com/interview/2502/http://www.coolinterview.com/interview/2502/http://www.coolinterview.com/interview/2501/http://www.coolinterview.com/interview/2501/http://www.coolinterview.com/interview/2500/http://www.coolinterview.com/interview/2500/http://www.coolinterview.com/interview/2499/http://www.coolinterview.com/interview/2499/http://www.coolinterview.com/interview/2499/http://www.coolinterview.com/interview/2498/http://www.coolinterview.com/interview/2498/http://www.coolinterview.com/interview/2498/http://www.coolinterview.com/interview/2497/http://www.coolinterview.com/interview/2497/http://www.coolinterview.com/interview/2497/http://www.coolinterview.com/interview/2496/http://www.coolinterview.com/interview/2496/http://www.coolinterview.com/interview/2496/http://www.coolinterview.com/interview/2016/http://www.coolinterview.com/interview/2016/http://www.coolinterview.com/interview/2016/http://www.coolinterview.com/interview/2015/http://www.coolinterview.com/interview/2015/http://www.coolinterview.com/interview/2015/http://www.coolinterview.com/interview/2014/http://www.coolinterview.com/interview/2014/http://www.coolinterview.com/interview/2014/http://www.coolinterview.com/interview/2013/http://www.coolinterview.com/interview/2013/http://www.coolinterview.com/interview/2013/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2013/http://www.coolinterview.com/interview/2013/http://www.coolinterview.com/interview/2014/http://www.coolinterview.com/interview/2014/http://www.coolinterview.com/interview/2014/http://www.coolinterview.com/interview/2015/http://www.coolinterview.com/interview/2015/http://www.coolinterview.com/interview/2016/http://www.coolinterview.com/interview/2016/http://www.coolinterview.com/interview/2016/http://www.coolinterview.com/interview/2496/http://www.coolinterview.com/interview/2496/http://www.coolinterview.com/interview/2496/http://www.coolinterview.com/interview/2497/http://www.coolinterview.com/interview/2497/http://www.coolinterview.com/interview/2497/http://www.coolinterview.com/interview/2498/http://www.coolinterview.com/interview/2498/http://www.coolinterview.com/interview/2498/http://www.coolinterview.com/interview/2499/http://www.coolinterview.com/interview/2499/http://www.coolinterview.com/interview/2499/http://www.coolinterview.com/interview/2500/http://www.coolinterview.com/interview/2500/http://www.coolinterview.com/interview/2501/http://www.coolinterview.com/interview/2501/http://www.coolinterview.com/interview/2502/http://www.coolinterview.com/interview/2502/http://www.coolinterview.com/interview/2502/http://www.coolinterview.com/interview/2503/http://www.coolinterview.com/interview/2503/http://www.coolinterview.com/interview/2504/http://www.coolinterview.com/interview/2504/http://www.coolinterview.com/interview/2505/http://www.coolinterview.com/interview/2505/http://www.coolinterview.com/interview/7472/http://www.coolinterview.com/interview/7472/http://www.coolinterview.com/interview/7472/http://www.coolinterview.com/interview/12729/http://www.coolinterview.com/interview/12729/http://www.coolinterview.com/interview/12729/http://www.coolinterview.com/interview/12729/http://www.coolinterview.com/interview/12729/http://www.coolinterview.com/interview/13987/http://www.coolinterview.com/interview/13987/
  • 7/28/2019 unixfaq

    2/7

    What will the following command do? View Answer

    Write a command to display a file?s contentsin various formats?

    View Answer

    What is the use of the command "ls -x chapter[1-5]"

    Answer : Yes you are correct. It stands for listing the files Chapterwith suffix 1 to 5 but it will display the files in columns as with-x option.

    ls -x chapter[1-5] will show list entries by lines instead of by columnsnamed with chapter1 to chapter5

    Explain kill() and its possible return values.

    Answer : There are four possible results from this call:?kill()? returns 0. This implies that a process exists with the given PID, andthe system would allow you to send signals to it. It is system-dependentwhether the process could be a zombie.?kill()? returns -1, ?errno == ESRCH? either no process exists with thegiven PID, or security enhancements are causing the system to deny itsexistence. (On some systems, the process could be a zombie.)?kill()? returns -1, ?errno == EPERM? the system would not allow you to killthe specified process. This means that either the process exists (again, itcould be a zombie) or draconian security enhancements are present (e.g.your process is not allowed to send signals to

    How to terminate a process which is running and the specialty oncommand kill 0?

    Answer : With the help of kill command we can terminate the process.

    Syntax: kill pidKill 0 - kills all processes in your system except the login shell.

    What is redirection?

    Answer : Directing the flow of data to the file or from the file for input or

    output.Example : ls > wc

    What areshellvariables?

    Answer : Shell variables are special variables, a name-value pair created and

    maintained by the shell.

    http://www.coolinterview.com/interview/2011/http://www.coolinterview.com/interview/2011/http://www.coolinterview.com/interview/2011/http://www.coolinterview.com/interview/2010/http://www.coolinterview.com/interview/2010/http://www.coolinterview.com/interview/2010/http://www.coolinterview.com/interview/2500/http://www.coolinterview.com/interview/2500/http://www.coolinterview.com/interview/2500/http://www.coolinterview.com/interview/2500/http://www.coolinterview.com/interview/2010/http://www.coolinterview.com/interview/2010/http://www.coolinterview.com/interview/2010/http://www.coolinterview.com/interview/2011/http://www.coolinterview.com/interview/2011/
  • 7/28/2019 unixfaq

    3/7

    Example: PATH, HOME, MAIL and TERM

    How to switch to a super user status to gain privileges?

    Use ?su? command. Thesystemasks for password and when valid entry is made

    the user gains super user

    How does the kernel differentiate device files and ordinary files?

    Kernel checks 'type' field in the file's inode structure.

    How many prompts are available in a UNIX system?

    Two prompts, PS1 (Primary Prompt), PS2 (Secondary Prompt).

    command prompt and GUI

    Name the data structure used to maintain file identification?

    ?inode?, each file has a separate inode and a unique inode number.

    Is ?du? a command? If so, what is its use?

    Yes, it stands for ?disk usage?. With the help of this command you can find thedisk capacity andfree spaceof the disk.

    Is it possible to restrict incoming message?

    Yes, using the ?mesg? command.

    $ mesg -n

    Is it possible to create new a filesystemin UNIX?

    Yes, ?mkfs? is used to create a newfile system.

    Syntax ismkfs [V] [-t ftype] [fs-option] filesys [block]

    -v produce verbose output-t fstype specifies the type to file system, default is ext2

    What will the following command do?

    http://www.coolinterview.com/interview/2499/http://www.coolinterview.com/interview/2499/http://www.coolinterview.com/interview/2499/http://www.coolinterview.com/interview/2015/http://www.coolinterview.com/interview/2015/http://www.coolinterview.com/interview/2015/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2012/http://www.coolinterview.com/interview/2015/http://www.coolinterview.com/interview/2499/
  • 7/28/2019 unixfaq

    4/7

    $ echo *It is similar to 'ls' command and displays all the files in the currentdirectory.

    Write a command to display a file?s contents invarious formats?

    $od -cbd file_namec - character, b - binary (octal), d-decimal, od=Octal Dump.

    Which command is used to delete all files in the current directory and allits sub-directories?

    rm -r *

    go to particular directory and type

    rm -rf *

    Write a command to kill the last backgroundjob?

    Kill $!

    What is the difference between cat and more command?

    Cat displays file contents. If the file is large the contents scroll off the screenbefore we view it. So command 'more' is like apagerwhich displays the contentspage by page.

    What difference between cmp and diff commands?

    cmp - Compares two files byte by byte and displays the first mismatchdiff - tells the changes to be made to make the files identical

    http://www.coolinterview.com/interview/2010/http://www.coolinterview.com/interview/2010/http://www.coolinterview.com/interview/2010/http://www.coolinterview.com/interview/2008/http://www.coolinterview.com/interview/2008/http://www.coolinterview.com/interview/2008/http://www.coolinterview.com/interview/2007/http://www.coolinterview.com/interview/2007/http://www.coolinterview.com/interview/2007/http://www.coolinterview.com/interview/2007/http://www.coolinterview.com/interview/2008/http://www.coolinterview.com/interview/2010/
  • 7/28/2019 unixfaq

    5/7

    Explain the steps that ashellfollows while processing a command.

    After the command line is terminated by the key, the shell goes ahead withprocessing the command line in one or more passes. The sequence is welldefined and assumes the following order.

    Parsing: The shell first breaks up the command line into words, using spaces andthe delimiters, unless quoted. All consecutive occurrences of a space or tab arereplaced here with a single space.Variable evaluation: All words preceded by a $ are evaluated as variables, unlessquoted or escaped.Command substitution: Any command surrounded by back quotes is executed bythe shell which then replaces the standard output of the command into thecommand line.Wild-card interpretation: The shell finally scans the command line for wild-cards(the characters *, ?, [, ]). Any word containing a wild-card is replaced by asorted list of filenames that match the pattern. The list of these filenames thenforms the arguments to the command.PATH evaluation: It finally looks for the PATH variable to determine the sequenceofdirectoriesit has to search in order to hunt for the command.

    How is the command ?$cat file2 ? different from ?$cat >file2 and >>redirection operators ?

    is the output redirection operator when used it overwrites while >> operatorappends into the file.

    ->$cat file2 displays the all ready created file.i.e the contents of particular filewhich we mention.->$cat > file2, it is used for creating a new file.

    ->$cat >> file2,it is used for appendingi.e it is used to insert the extra info intalready created file.

    Which of the following commands is not a filterman , (b) cat , (c) pg , (d) head

    Ans: manA filter is a program which can receive a flow of data from std input, process (orfilter) it and send the result to the std output.

    What does the command ?$ls | wc ?l > file1? do?

    ls becomes the input to wc which counts the number of lines it receives as inputand instead of displaying this count , the value is stored in file1

    http://www.coolinterview.com/interview/2004/http://www.coolinterview.com/interview/2004/http://www.coolinterview.com/interview/2004/http://www.coolinterview.com/interview/2004/http://www.coolinterview.com/interview/2004/http://www.coolinterview.com/interview/2004/http://www.coolinterview.com/interview/2004/http://www.coolinterview.com/interview/2004/
  • 7/28/2019 unixfaq

    6/7

    What does the command ? $who | sort ?logfile > newfile? do?

    The input from a pipe can be combined with the input from a file . The trick is touse the special symbol ?-? (a hyphen) for those commands that recognize thehyphen as std input.

    In the above command the output from who becomes the std input to sort ,meanwhile sort opens the file logfile, the contents of this file is sorted togetherwith the output of who (rep by the hyphen) and the sorted output is redirected tothe file newfile.

    What is the significance of the ?tee? command?

    It reads the standard input and sends it to the standard output while redirectinga copy of what it has read to the file specified by the user.

    tee

    Explain the following commands.

    $ ls > file1$ banner hi-fi > message$ cat par.3 par.4 par.5 >> report$ cat file1>file1$ date ; who$ date ; who > logfile$ (date ; who) > logfile

    $ ls > file1 -> output of ls is redirected to file file1$ banner hi-fi > message -> the banner pattern of "hi-fi" redirected to filemessage$ cat par.3 par.4 par.5 >> report -> contents of files par.2 par.4 par.5 appendedto file report$ cat file1>file1 -> file emptied$ date ; who -> shows date and then who-all-logged-in$ date ; who > logfile -> shows date and output of who-all-logged-in redirected

    to file logfile$ (date ; who) > logfile -> output of date and who-all-logged-in redirected to filelogfile

  • 7/28/2019 unixfaq

    7/7

    Construct pipes to execute the followingjobs.

    1. Output of who should be displayed on the screen with value of total number ofusers who have logged in displayed at the bottom of the list.2. Output of ls should be displayed on the screen and from this output the lines

    containing the word ?poem? should be counted and the count should be stored ina file.3. Contents of file1 and file2 should be displayed on the screen and this outputshould be appended in a file. From output of ls the lines containing ?poem?should be displayed on the screen along with the count.4. Name of cities should be accepted from the keyboard . This list should becombined with the list present in a file. This combined list should be sorted andthe sorted list should be stored in a file ?newcity?.5. All files present in a directory dir1 should be deleted any error while deletingshould be stored in a file ?errorlog?.

    1.who|wc -l2.ls|wc -c|grep "^poem$" >file3.ls|wc -c|cat>file1>>file2

    4.cat>>$city| sort >newcity5.rm -r > errorlog

    http://www.coolinterview.com/interview/1997/http://www.coolinterview.com/interview/1997/http://www.coolinterview.com/interview/1997/http://www.coolinterview.com/interview/1997/http://www.coolinterview.com/interview/1997/http://www.coolinterview.com/interview/1997/http://www.coolinterview.com/interview/1997/http://www.coolinterview.com/interview/1997/