Sie sind auf Seite 1von 6

Basic UNIX Material For Beginners

1. How do you search for a particular pattern in a file?


There are many ways to search for a particular pattern in a file.
From the command prompt use grep command to find the pattern
E.g.: grep pattern file_name

When the file is in the editing mode(vi editor) come to non-editing mode(by pressing
escape key). /pattern will find next line matching Pattern (Pattern is the text you are
searching for) and? Pattern will find previous line matching pattern.

2. How do you list all the processes?


Ps e lists all the processes currently running.

3. How do you list the directory structure?


ls l directory_name| grep ^d
The mode printed under l option consists of 10 character.For the directories the first
character is d.The long listing listing all the
ls F directory_name |grep \/
-F options marks directories with trailing slash(/).Filter this list by greping the (/).Use escape
sequence character \ to suppress the meaning of / character

4. cp fil1 fil2 command is failed, what are the possible chances for failing?
cp could fail because of the following reason
The destination file directory in to which the file is copied may not have write (w)
permission.
The source file may not have read permission(r)
The source file may not be present.
The destination directory may not have enough space (Space can be checked with df k)

5. How to search for a file which created in December?


-- File creation time is not stored in UNIX. You can only check files modified in December with ls
l | grep Dec
ls -l | tr -s " " | cut -d " " -f6

6. About Shell Script?

An ordinary file containing a set of commands, which is executed in interpretive manner in a


sub shell

7. What does the "Fork" command do?


Fork () is a system call which is used to create new processes. The new process also called
child process is the exact copy of the calling process (Parent process).

8. What is the relation between the parent and child process created by "fork"?
The child process is the exact copy of the parent process.The child process inherits real
userid,real groupid,effective userid,effective groupid,Open files of its parent,current
directory,root directory, file mode creation mask,as well as the exported variables.
The child process differs from the parent process in the following ways
The child process has a unique process ID, which does not match any active process
groupid.
The child process has different parent process id.
The child process has its own copy of parents file descriptors and directory streams.

9. what are the popular shells available in the market? Which shell have you worked on ? What
is diff between <x> shell and <y>shell ?
Bourne shell, C shell and Korn shell

Job control
Aliases
Shell functions
"Sensible" Input/Output redirection
Directory stack
Command history
Command line editing
Vi Command line editing
Emacs Command line editing
Rebindable Command line editing
User name look up
Login/Logout watching
Filename completion
Username completion
Hostname completion
History completion

sh
N
N
Y(1)
Y
N
N
N
N
N
N
N
N
N
N
N
N

csh
Y
Y
N
N
Y
Y
N
N
N
N
Y
N
Y(1)
Y(2)
Y(2)
N

ksh
Y
Y
Y
Y
Y
Y
Y
Y
Y
N
Y
N
Y
Y
Y
N

Fully programmable Completion


Mh Mailbox completion
Co Processes
Builtin artithmetic evaluation
Can follow symbolic links invisibly
Periodic command execution
Custom Prompt (easily)
Sun Keyboard Hack
Spelling Correction
Process Substitution
Underlying Syntax
Freely Available
Checks Mailbox
Tty Sanity Checking
Can cope with large argument lists
Has non-interactive startup file
Has non-login startup file
Can avoid user startup files
Can specify startup file
Low level command redefinition
Has anonymous functions
List Variables
Full signal trap handling
File no clobber ability
Local variables
Lexically scoped variables
Exceptions

N
N
N
N
N
N
N
N
N
N
sh
N
N
N
Y
N
N
N
N
N
N
N
Y
N
N
N
N

N
N
N
Y
N
N
N
N
N
N
csh
N
Y
N
N
Y
Y
Y
N
N
N
Y
N
Y
N
N
N

N
N
Y
Y
Y
N
Y
N
N
N
sh
N(5)
Y
N
Y
Y(7)
Y(7)
N
Y
N
N
Y
Y
Y
Y
N
N

Key to the table above.


Y

Feature can be done using this shell.

Feature is not present in the shell.

Feature can only be done by using the shells function


mechanism.

The readline library must be linked into the shell to enable


this Feature.

Notes to the table above


1. This feature was not in the orginal version, but has since become
almost standard.
2. This feature is fairly new and so is often not found on many
versions of the shell, it is gradually making its way into
standard distribution.

3. The Vi emulation of this shell is thought by many to be


incomplete.
4. This feature is not standard but unoffical patches exist to
perform this.
5. A version called 'pdksh' is freely available, but does not have
the full functionality of the AT&amp;T version.
6. This can be done via the shells programmable completion mechanism.
7. Only by specifing a file via the ENV environment variable.

10.How to delete a directory which is located in some other path?


rm r /complete_path/dirctrory_name

11.

How to find for a file? How will you find all files which are NOT accessed in
days ?
find directoryname name file_name print
find directoryname atime +10 -print

12.How to read the compressed file?


By using zcat
zcat filename.Z | pg

13.How to copy contents of file 'a' and file 'b' to the file 'ab'?
cat a b > ab

14.How to see a file growing?


tail f filename

the last 10

15.What is a shell?
Shell is a command line interpreter of the Unix system

16.Copy data from one file to other in Vi


yank the lines to a named buffer using a10yy and put in another file with ap. Just yanking using
10yy will work only within the file.

1. Transfer of file from UNIX to Excel use split or zip?


Split command will split the file into many files with specified line count/ size.However Zip
utility will only reduce the size of the file on the disk.
The spread sheet application has limitations in number of rows in a file.
In this case it is better to split the file based on line count.
If the table has 1 million rows, splitting it with 10000 lines all will create 100 files that is difficult
to handle. It will be better to split at say 60000 lines as excel can handle 65000 rows. Then
you will get less than 20 files to handle.

2. How do you view a long file in Vi and search for a string?


Check specifying the directory for buffer file in vi.

3. What is Zombie process


A process finishes when it calls the exit system call with a parameter to tell its parent
process, the process that started it off, whether it was sucessful or not.
When this happens the kernel releases everything used by that process, except, that is, its
slot in the process table.
At this point the process is a Zombie process; it has completed and the only thing left is its
entry in the system process table. It will stay a zombie until the thing that started the process
in the first place (called the parent process) checks on that entry in the process table.
That entry is left there so that the parent process can pick up that exit parameter and find
out whether its child succeeded or not.

List of commonly asked Unix Commands


1. Ls lists content of directory
2. Cat concatenate and display files
3. Tee-Utility by which you can save the standard output in a file, as well as display it on the
terminal (or pipe it into another process)

4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.

Find find files


Du -summarizes disk usage
Df- displays the number of free disk blocks and files
Grep search a file or pattern
vi commands
cut- cut out selected field of each line in a file
ps reports process status
which locates a command and display its path_name
Bg runs the current job or the specified job in the back ground
Kill- terminates or signal process
Sed- stream editor to edit text files
Awk-pattern scanning and processing language
Tail display the last part of a file
Chgrp- change file group ownership
Chown-change file ownership
Who-lists all the users who have logged into the system along with terminal type and login
date and time
Diff & cmp Diff displays the line by line differences between pairs of text files. Cmp
compares the two files and writes to the standard output the byte and the line numbers at
which the first difference occurred.
Finger Displays information about local and remote users.The command displays in multi
column format the information about logged in user like user name,users full name,login
time,termainal name and so on.
Fork-Creates a new process
To debug shell scripts set x
State of the process
Xargs - The xargs utility constructs a command line consisting of
the utility and argument operands specified followed by as
many arguments read in sequence from standard input as will
fit in length and number constraints specified by the
options. The xargs utility then invokes the constructed
command line and waits for its completion.
Ex : ls abc* | xargs rm

25. Uname the uname utility prints the information about the current system on the statndard
output
26. cron, crontab- Cron command starts a process that executes commands at specified dates
and time.Crontab utility manages users with cron by copying,creating,listing and removing
crontab files
27. umask-Gets or sets the file mode creation mask
28. join-A join of two relations specified by the lines of file1 and file2
29. Nice-Used to invoke a command with altered scheduling priority
30. Nohup-Runs a commnd immune to hangups
31. Uniq- filters out repeated lines in a file

Das könnte Ihnen auch gefallen