Beruflich Dokumente
Kultur Dokumente
Logging in
•Find a computer that is available for your use. If a workstation is available, a login prompt
should be displayed. For example, on the Umber workstation the login prompt looks like this:
login:
•Type your account name. If you make a mistake, type control-U and start over.
•Press the Return key. This tells the computer that you have finished entering your account
name. The computer should then prompt you with "Password:"
•Type your password and press the Return key. The letters you type should not appear on the
screen; this helps you to keep your password a secret.
•If you log in successfully, you should see a Unix prompt appear at the left side of your screen
$ ls (short listing)
Switches –
-l long listing
-a All hidden files.
-r Display in reverse order
-R Recursive listing (Tree structure)
mv filename1 filename2 –
moves a file (i.e. gives it a different name, or moves it into a different directory
e.g. mv f1 f2
e.g. rm f1
finger username --- gives you lots of information about that user, e.g. when they
last read their mail and whether they're logged in. Often people put other
practical information, such as phone numbers and addresses, in a file called
.plan. This information is also displayed by 'finger'.
passwd --- lets you change your password.
e.g. $ passwd
old password :
new password :
Types of Users –
There are three kind of users in Unix.
•Owner (u)
•Group (g)
•Others (o)
We can create different kind of groups inside unix shell with different kind of permissions
and utilities.
Owner is a user who is logged in. Group users are the users who belong to same group
created by administrator, and others are the all users other than your login.
Permissions –
There are 3 classes of file permission. For three kind of users. To change permission of the
file. command used is –chmod
Permission Symbol Octal no.
read r 4
write w 2
Execute x 1
Pipes –
Pipes are the utilities through which user can make composite commands in such a manner
as output of one command will be treated as input for next command.
Command 1 | command 2
e.g. ls –l |more
Filters –
Are the utilities to search a particular pattern in the input.
e.g. – grep “this” file1 (will search all the lines match with the pattern “this”)
grep – it is a type of filter which is used to search a particular (one) pattern in a file.
grep “pattern” <filename>
e.g. – grep “is” data (will search all the lines contain “is” word)
egrep – it is a type of filter which is used to search more than one pattern in a file.
egrep “pat1|pat2…” <filename>
e.g. – egrep “is | that” data
File Comparisson –
1. cmp – this is a command used to compare file character wise and stop comparison if it finds
first difference.
cmp <file1> <file2>
2. comm – used to compare two files. But both files should be sorted. It gives individual lines
from 1st file, 2nd file and same lines of both files.
comm <file1> <file2>
diff – used to compare two files line by line if they are sorted and give only difference.
diff <file1> <file2>
Cut – This is a filter command used to cut no. of characters and fields from a file.
-c Character cut
-f Field Cut
-d IFS
Cut –c(no of characters) <file>
e.g. cut –c1-3 data “will display 1 to 3 starting characters of each line
from data file.”
Vi data
A:200:100:20
B:10:20:30
C:12:11:23
Display 2nd and 3rd field from data file
Switch –
-o used to store output of sort command into a file
sort –o file1 file1 # will store sorted output in file1 itself
-r used to sort file in reverse order
sort –r file1
-n used for numeric sort
sort –n file1
Write sort command to sort data file by salary which is 2nd column in file
ln – used to create symbolic link for a file. Symbolic link is a technique through which one file can
be accessed at many places by creating logical links in such a way –
- physically it will be stored at one place
- logically accessible by many places.
- changes to one link will reflect to the all links
Note - ls –l will automatically update link column
ln <source file> <link file>
Communication in Unix –
Unix provides two kind of communication
•on-line communication – In which it is required that both users i.e. sender or receiver should
be login.
commands –
•Write – command to send online messages to any user
write <username>
•Wall – command used to broadcast any message to all users working with unix. It is used by
administrator.
•Mesg – this is used to off or on the permission for online communication.
mesg <permission>
e.g. mesg y
•Off- Line Communication – in which it is not required that receiver should be logged in. the
messages stored into the inbox or mailbox of the user.
•Mail – this is used to send off line messages like email.
mail <username>
Sending Mail
Say I want to send a short note to the person with the email address
nobody@december.com. Here is an example of how I would do this:
$ mail nobody@december.com
Subject: Hi
This is just a short note to say hello. I don't have anything else right now. .
Cc:
Note: If you delete the source file or move it to a different location, your symbolic file will not
function properly. You should either delete or move it. If you try to use it for other purposes
(e.g., if you try to edit or execute it), the system will send a "file nonexistent" message.
hard link
A hard link is essentially a label or name assigned to a file. Conventionally, we think of a file
as consisting of a set of information that has a single name. However, it is possible to create
a number of different names that all refer to the same contents. Commands executed upon
any of these different names will then operate upon the same file contents.
To make a hard link to an existing file, enter:
ln oldfile newlink
This will create a new item in your working directory, newlink, which is linked to the contents
of oldfile. The new link will show up along with the rest of your filenames when you list them
using the ls command. This new link is not a separate copy of the old file, but rather a
different name for exactly the same file contents as the old file. Consequently, any changes
you make to oldfile will be visible in newlink.
You can use the standard Unix rm command to delete a link. After a link has been removed,
the file contents will still exist as long as there is one name referencing the file. Thus, if you
use the rm command on a filename, and a separate link exists to the same file contents, you
have not really deleted the file; you can still access it through the other link. Consequently,
hard links can make it difficult to keep track of files. Furthermore, hard links cannot refer to
files located on different computers linked by NFS, nor can they refer to directories.