Sunteți pe pagina 1din 50

Unix

Logging In and Out


As

a multi-user system, when connected


to UNIX System through remote
terminal, it will prompt you as:
login: student <Enter>
password: _
Here password is not displayed, and
cursor is on its place as it is.
$ is the default prompt, offered by UNIX
System.

Logging In and Out


passwd is

the simple command in UNIX


System to change current user password.

Introductory Commands
date:

? Date is the command used to display system


date and time.
clear:

? Clear is one of the commands to clear the


screen.
? Another command works similarly is
tput clear

Introductory Commands
who
who

am I

? Who is the command which will display user


information logged on to the UNIX System,
where as who am i is another command
which will display information of only a
person who is executing the command.

Introductory Commands
man <command>

? Man is a simple utility which will display help


for any command specified as an argument.
? Another pattern used in some Linux versions
are:
<command> --help

date Command
With date

command

? %m:To display month in digit.


? %h:To display month name
? %d:To display day in digit.
? %H:To display hour digits
? %M:To display minute digits
? %S:To display second digits
date

+%h %d %H %M

who Command
With who

command:

? -H: will display headings for each column


? -u: will display more details including PID.

tty Command
With tty

command:

? It stands for (TeleTYpe)


? Used to display terminal device on UNIX
System.

uname Command
With uname

command:

? uname will simply display domain name of


UNIX System on which you have logged on.
? uname n is the option using which machine
name on network.
? uname r will display version of your
operating system

echo Command
With echo

command:

? Is used to repeat and display again on screen,


passed as argument.
echo Good Morning
echo Good
echo Good

Morning
Morning

tput Command
With tput

command:

? Is the command for cleaning the screen.


? Another use is to position to relocate cursor.
tput cup 10 20

bc A UNIX Calculator

With bc command:
? Is used as calculator in UNIX System.

bc <enter>
12 + 5 -> 17
12*12 ; 2^32
x=3 ; y=4 ; z=5
p=x+y+z
p -> 12

HOME Directory
When

you log in to the system, UNIX


automatically places you in a directory
called a home directory.
It is created by the System when the user
account is created.
? echo $HOME

Checking path and changing directory


Checking the current directory position:

? $ pwd
You

can move around in the file system by


using the cd command.
? $ cd <directory name>
? $ cd /bin
? $ cd /

Making Directories
Like DOS, directories

can be created with

the mkdir command.


The command is followed by the names
of the directories to be created.
? $ mkdir first
? $ mkdir second third fourth

Removing Dictionary
The rmdir

command removes

directories.
? You cant delete a directory unless it is empty.
? Even directory cant be removed where your
present command is.

File Listing
This

is simple and powerful command to


get list of files and directories.
? $ ls
? $ ls <directory name>
? $ ls x (Multiple column output)
? $ ls F (Identifying Directories and
Executables with / and * respectively)
? $ ls a (Shows Hidden Files presiding .)

File Listing
? -r (Reversing the sort order)
? ls xa <directory name> (Subdirectory
Listing )
? ls xaR
? ls l (Long Listing)
? ls t (Sorting files by modification time)
? ls u (Sorting files by access time)
? ls i (Shows inode number for file)

Creating Files
Cat

is useful to create as well as display


files in UNIX System.
? $ cat > f1.txt (Creates f1.txt file)
? $ cat f1.txt (Displaying File Contents)
? $ cat < f1.txt (Alternate Command)

spell Command
With spell

command:

? Is used to check spell error of file passed as


argument.
spell typescript

? Default dictionary used is US, to convert it to


British Dictionary, -b option is used.

Copying Files
The cp command copies a file or a group of
files to destination.
For required two parameters, if two ordinary
files are given, first is copied to second.

? $ cp f1.txt f2.txt

If destination file exists, will be overwritten


without warning.
? $ cp f1.txt first
? $ cp f1.txt first/f2.txt

-i

is the option used as interactive copying


option.
It warns user before overwriting the
destination file.
? $ cp i f1.txt f2.txt

Removing Files
Files

can be deleted with rm.

? $ rm <file> <file>
? $ rm * (It wont warn you!!)
? $ rm i * (Interactive Remove Process)
? $ rm r * (Removes files and directories
recursively)

Renaming Files
mv

is very similar to MOVE command in


DOS.
It has two purposes, renaming file and
moving group of files and directories to
destination directory file.
? $ mv f* second
? $ mv test.script new.script
? $ mv second sec

More.
If

the file is too large for its contents to fit


in one screen, it will scroll off your screen
when you view it with cat.
more allows user to view a file, one
screen at a time.
Original pager was pg with UNIX System.

f is the option to scroll the screen forward


and b for backword.
10G goes to line number 10
/<pattern> - searches for pattern forward
?<pattern> - searches for pattern backward
n repeats last search forward
N repeats last search backword
q Quit from more

Printing File
No

user is allowed direct access to the


printer.
Instead, one has to spool a job along with
others in a print queue.
lp (Line Printing) is the command (or lpr)
to fire print job to the System.
? $ lp test.script

? $ lp dlaser test.script (specifies the


specific printer name laser)
? $ lp tTitle Here test.script (Prints title
on the first page of the print.
? $ lp n4 test.script (Specifies the number of
copies 4)
? $ cancel laser (Cancels current job on
printer laser)

Know your FILE type


There

are basically three types of files in


UNIX System
? Ordinary
? Directory
? Device

file

<filename|*> is the command to


identify and display the type of file.

System

is able to differentiate between


text file, C file, FORTRAN file, shell
program, executables, directories, empty
files etc.
Though this is not accurate utility with all
the flavors.

Counting on FILES
UNIX

has command wc (Word Count),


to count lines, words and characters,
depending on the options used.
It takes one or more files as arguments.
-l is the option to count number of lines
-w counts total number of words
-c counts total number of characters.

Splitting Files into Multiples


When it

becomes impossible to work


with large files, split command is used to
break files into multiple files.
? $ split <filename>

It

splits files default into files namely xaa,


xab, xac and so on. (Max. : 676)
Specify additionally file lines as options to
over ride default size of 1000 lines.
? $ split 15 <filename>

To override predefined x as filename,

specify file name as third argument.


? $ split <file1> <file2>
This

will create files with name file2aa,


file2ab, file2ac and so on.

Comparing Two Files


To

compare file with another for finding


dissimilarity in both, cmp command is
used:
? $ cmp <file1> <file2>

The

two files are compared byte by byte,


and the location of the first mismatch is
echoed to the screen.
It terminates matches after first
mismatch.

-l

is the option which gives a detailed list


of the byte number and the differing bytes
in octal for character that differs in both
the files.

Finding Commons
Comm compares

each line of first file


with its corresponding line in second file
and generates output.
Output is divided into three columns
separated by TABs,
? First column contains unique lines in first file.
? Second column contains unique lines in the
second file
? Third column contains unique lines in both
the files.

To

drop particular column, -1 | -2 or 3


are the options which can be used as
parameters.
? $ comm f1 f2 1

Pattern Matching with Wild Cards


UNIX

System offers several wild card


patterns to mach the criteria
? * : Matches any number of character including
none
? ? : Matches a single character
? [abc] : Matches single character either a, b
or c
? [!abc] : Matches single character but not a, b
or c

? [x-z] : Matches a single character that is within


the ASCII range of character x and z
? [!x-z] : Matches a single character that is not
within the ASCII range of characters x and z

Escaping
It

is generally accepted principle that


filenames shouldnt contain the shell
meta-characters.
If then do, while accessing, \ is used to
escape the sequence (original) meaning of
meta-characters.
Enter key is also escaped!!
? $ wc l f1 \<enter>

Guess

the output of the following


command:
? $ echo *

Escaping

<Escape Applied>

spaces is also allowed here.

? $ echo This is \ \ \ Space

Redirection
Guess

the output of commands:

? $ cat
? $ wc
Consider

the input and output for these:


When input is taken from multiple
sources, a file as well as standard input,
the symbol is used.

? $ cat f1
? $ ws f2
As

standard inputs are altered, standard


outputs can also be altered as:
? $ wc f1 > f3
? $ wc f2 >> f3
? $ cat f* > outputFile

Two

or more commands can also be


combined and the aggregate output is
diverted to file.
? $ (ls l;who) > newFile

cal for Calendar


cal command

? $ cal
? $ cal 1993

is used to display calendar.


<Current Month Calendar>
<Specific years whole cal>

-1 is the option to display current month


-3 is the command to display
previous/current/next month
-s displays Sunday as first week day
-m displays Monday as first week day
-j as Julian Date format
-y displays calendar of current year

Tees (And Not Trees)


UNIX

provides a feature tee - by which


you can save the standard output in a file,
as well as display it on the terminal or
pipe it to another process.
tee uses standard input and standard
output, which means that it can be placed
anywhere in a pipeline.
tee breaks up the input into two
components, one is saved in a file and
another is passed to standard output.

? $ ls | tee file.lst
? $ cat One | wc l | tee temp.wc
? $ cat Five | wc l | tee a temp.wc
? $ cal | tee a file1 > file2

Command Substitution
When

the command is enclosed within


the pair of back quotes, the shell executes
the command first, and the command test
is replaced by the output command.
This is case to executing command within
another.

? $ echo Todays Date Is: ; date


? $ echo Todays Date Is: `date`
? $ echo There are `ls |wc l` files in
current directory

S-ar putea să vă placă și