Unix Basics

Unix & Concepts

Features of Unix
* Multi-user
* Multitasking
* Support for Networking
* Programming Facility

Windows and Unix OS.
* (Table…)
* Menus and Icons
* Requires Constant Attention
* Scripting

Structure of Unix Operating System

Structure of Unix OS

Understanding the Unix commands

ls - Lists all the files & directories
cat - used for displaying and also creating new files.
grep - checks for the pattern in the specified file
file - gives the details of the file i.e,,, txt, exe, gif as such.
noclobber - prevents the accidental overwriting into a file .
ps - Lists all the commands that are currently running
echo - Displays all the arguments on the screen
uname - Gives the version number of the shell / kernel
who - Displays all the current users of the system
spell - Checks for all the mistakes in a given file document
pwd - Displays the current working directory
home - Displays the home directory which is decided by the administrator.
cmp - Compares two files and gives the corresponding output.
comm - Find the common text between the two files and gives the corresponding output.
pr - Paginating of files and adds an appropriate headers and footers
head - Displays top of the file
tail - Displays the bottom of the file
cut - Used to extract specific columns of the files
paste - Pastes files vertically rather than horizontally as it is usually done .
sort - Performs its usual sorting functions with variable length records,it comes with a lot of options.

Navigating the File System

* Redirection operators.(> , < , >> )
* Redirection of standard input ,output and standard error.
* Managing files and directories ( cd , pwd )
* Create/delete directory ( mkdir , rmdir )
* Create/delete files.( rm )
* Move/copy files.( mv , cp)
* In the current directory mv is used for renaming of files.

File Permissions
ls –l
-rwx-rw-rw- sunil may 13:55 sun1

Changing File Permissions ( chmod )
U-user + à assign r- read
g-group - à assign w- write
O-others = à assign x- execute.
a-all

Octal notation.
1.Read permission 4
2.Write permission 2
3.Execute permission 1

Syntax: chmod category operation permission file
chmod u + x sun1
chmod ugo = r sun1
chmod 6 6 6 sun1

Pipelines and tees
Pipeline :
* A sequence of two or more commands used with the | symbol , so that the input of one command comes from the output of the other.
* No intermediate files need to be created during the process.
* Example : $ who | wc –l
45

Tees :
* Unix provides a feature by which u can save the standard output in a file , as well as display

it on the terminal
* Tees breaks up the input into two components, one component is saved in the file , and the other is connected to the standard output.
* No filtering is done by tee it gives out exactly what it takes.
* Example: $ who | tee user. lst
sunil tty1 october 1 14:32

Wild card characters

Wild card / Meta characters ( * , ? , [ ] )
* Matches Zero or many occurrences .
? Matches a single character
[ ] Matches a single character within the enclosed characters

Example1 : $ ls -x chap*
chap1,chap2 ,chap22,chap…..
Example2 : $ ls -x chap?
chap x chap y chapz
Example 3: $ls –x chap [ijk]

[!ijk] Matches a single character that is not an i,j or k
[x-z] Matches a single character i.e.., within the ASCII range of characters X to Z
[! x-z] Matches a single character i.e.,not within the ASCII range of characters X to Z

Escaping CHARACTER BACKSLASH (\)
A backslash is used to remove the characteristics of the wild card characters .
Example1: $ echo * $ echo \*
All the files in pwd displayed *

Example2: $ls –l char* $ls –l char\*

System Variables

Unix system is controlled by number of shell variables that are separately set by the system some during the booting process and some after logging.

set
path
home
logname
ps1
ps2
pwd

.profile
It is a script executed during login time. it alters the operating environment of a user , which

remains in effect throughout the login session.

$ cat .profile
# user $HOME /.profile –commands executed at login time
HOME =/one/sunil/progs
Path =$PATH: /home/bin/usr
Ps1=$ ( command prompt )
Ps2=> ( multi-line command )
Echo “today the date is ‘date’ “
Calendar

It is similar to that of an shell script where all the commands are inserted into single file as such and executed during login for a particular user.

Stty ( setting the terminal characteristics )
Depending upon the users choice different terminals are configured differently .
$stty –a
Speed 9600 baud ; erase=^\;quit=^d; …………………….

Aliases :
Alias lets u assign short hand names for commands u may be using quite frequently.
$ cd $1;ls –l
Replaced with : alias showdir = ‘ $ cd $1;ls –l ’

VI editor

i insert mode.
leave insert mode and go into command mode.
a append characters to the end of the line.
g Go to the bottom of the file.
? And / Used for searching of a word/text in a file.
r replace the letter that you are on with the one you type next.
x erase the character that you are on
dd delete the line that you are on. A number before dd deletes that number of lines
.yy copy the line you are on. A number before yy copies that number of lines.
p paste the line you are on below you.
P paste the line you are on above you.
:wq write and quit the file that you are editing.
:wq! write and quit the file that you are editing, even if it is designated as read only
:w! write to a read only file
:q quit.
:q! discard any editing and quit.

Process & Job control

Suspend a Job – A suspended job is not killed , neither running but it is stopped ( ( ctrl +Z ) )
Background Job –To restart a job in background which is suspended , $ bg .
Foreground Job -To bring the command to foreground , $ fg .
Run a job in background – We can directly run a process in the background
$ big_task &
Displaying current Jobs – shell displays all the jobs that are being run , jobs in background , jobs background , jobs stopped .
$ jobs
Killing a Job – kills the job that is either bg, fg, stopped.
•Kill % job number

Features of shell (Bourne shell )
Command line editing – alter wrongly typed commands using screen editing commands (ctrl+A , ctrl+B, ctrl+E ………)
History mechanism- reissue previously entered commands.
File name completion – automatically complete a filename ,when given a partial name.
Redirecting input and output – direct output from commands to files and vice-versa.
Run commands in background while carrying on with your normal interactive work.
Change prompt – you can always change the command prompt , with the system name , present directory , date other than the usual “ $ “.
Use the { and } to produce multiple results from a single command .

Shell programming
Shell scripts
A file containing shell commands is a shell script .It has its own built in programming language , thus it is able to analyze and execute shell commands one at a time .

Steps followed to create a shell script ,

Create a file with the commands which u wish to execute
Change the file access mode , executable file.
Type the name of the file to execute the commands in the script
We can also execute a shell script by giving the command
$ sh script.sh

Control statements ( if , while , for )
Syntax: if condition then Syntax: while condition
Statements do
elif condition then statements
Statements done
else
Statements
fi

Syntax: for var [ in list ] syntax :case expression in
do pattern 1)
Statements statements;;
Done pattern 2)
statements;;
esac

If list is omitted, $@ is assumed Otherwise ${ list[*] } Where list is an array variable.
The keywords break, continue, and return have the same meaning as in C/C++

Positional parameters
The read command allows you to prompt for input and store it in a variable .
Correct : read name incorrect : read $name.
$1 - $9 these variables are called the positional parameters .
$# the number of positional arguments given to this invocation of the shell.
$? the exit status of the last command executed status is 0 / 1
$$ the process number of this shell
$! the process id of the last command run in the background.
$* a string containing all the arguments to the shell, starting at $1.
$@ same as above, except when quoted.
Example : festival$ cat example_5args
echo The first five command line
echo arguments are $1 $2 $3 $4 $5
Initially only nine commands are available it can be increased to any number by using the SHIFT COMMAND.

Documentation

apropos - locate commands by keyword lookup /usr/bin/X11/dxbook
man - find manual information about commands

whatis - describe what a command is

whereis - locate source, binary, or man page for a program

--help - some Linux commands don’t have man pages but almost all of them support the help option.

style="display:block"
data-ad-client="ca-pub-9945402454384428"
data-ad-slot="3540880857"
data-ad-format="autorelaxed">