Manasa Panda Accelerant Software
Manasa Panda Accelerant Software
Manasa Panda Accelerant Software
Manasa Panda
Accelerant Software
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
UNIX
Overview of UNIX
Why UNIX ?
Basic UNIX commands
vi editor
Advanced UNIX
Shell scripting
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Overview
What’s UNIX ?
UNIX is the name of a computer operating system
and its family of related utility programs.
First developed in the 1960s
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
Names of some Op. Systems:
SUN : SunOS, Solaris
SGI : IRIX
IBM : AIX
HP : HP-UX
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
Advantages: Disadvantages:
1. Robust 1. Expensive
2. Reliable. 2. System administration needs
special skill
3. Scalable, multi-user 3. Multiple vendors
4. Multiple vendors
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Basic Unix Commands
cd - change directory
mkdir <dirname>- create the directory
mv - move a file or directory
cp - copy a file or directory
rm - remove a file or directory
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Basic Unix Commands
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Basic Unix Commands
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Basic Unix Commands
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
up/down arrows scroll up and down through most recent
commands
left/right arrows use for editing current line
grep takes only one search string.
grep can be used with these flags - c, i, v, n.
c = count; i= ignore cases ; v =inverse, n = line number
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
grep - command searches the given file for lines containing a
match to the given strings or words
Usage:
grep ‘string1’ filename
grep ‘string1 string2’ filename
cat filename | grep ‘string1’
more filename |grep ‘string1’
more filename |grep -i‘string1’ (-i -to ignore word case)
grep -i ‘string1’ filename
grep -i ‘string1’ *.csv (look for the string in all csv in the
present working directory)
grep -i ‘string1’ */*.csv (look for the string in all csv in
all directory)
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
find - The find command is used to locate files in Unix
Usage:
find . (will display the pathnames of all files in the current
directory and all subdirectories)
find / -name “filename” (look for the file in the all directories)
find pathname -name “filename”
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
du
The du command outputs the number of kilobytes used by each
subdirectory. Useful if you have gone over quota and you want to
find out which directory has the most files. In your home-
directory, type
% du -s *
The -s flag will display only a summary (total size) and the *
means all files and directories.
gzip
This reduces the size of a file, thus freeing valuable disk space.
For example, type
% ls -l science.txt
and note the size of the file using ls -l . Then to compress
science.txt, type
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
% gzip science.txt
This will compress the file and place it in a file
called science.txt.gz
To see the change in size, type ls -l again.
To expand the file, use the gunzip command.
% gunzip science.txt.gz
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
File Transfer
tar / untar - flags c (copy), x(extract),v(verbose), f(path)
usage: tar cvf dirname2.tar dirname1
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Shell Scripts
The shell is also a programming language that executes shell
scripts in interpretive mode i.e. one line at a time.
Bourne shell (sh) - original shell that came with UNIX.
Korn shell(ksh), C shell(csh), tcsh(super set of C-shell) - shells
developed later.
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Shell Scripts
#!/usr/bin/bash
echo 'Hello'
echo 'This is my first script'
echo 'Bye'
status=$?
echo "Exit Status : $status"
if [[ "$status" != "0" ]]
then
exit $status
fi
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
vi Editor
Create a new file/open an old file using vi editor :
Command: vi filename
Write to a file using vi editor :
Write mode: press ‘i’ or ‘a’, then start typing.
Go to command mode: press ‘ESC’
Save/abort a file:
Save: press : then w ; Abort: press : the q!
Search for a string in a file in vi editor:
press / then type the search string
Go to the end of a line: in command mode type $
Go to the beginning of a line: in command mode press 0
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
Go to nth line of a file: press : then n
Go to the end of a file: press ‘G’ or press : then $
Show line numbers of a file: press : then ‘set number’
Remove line numbers: press : then ‘set nonumber’
Delete a single character: press x when the cursor is on it.
Delete a line: press d twice on the line to be deleted.
Delete n lines: press n and then press d twice.
Copy n lines: press n and then press y twice, then press p
at the location you want to paste it.
Undo the last change: press u
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
Replace a character : press r, then the new character
To navigate the file: press h (for moving towards left)
press l (for moving towards right)
press k (for moving up)
press j (for moving down)
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
ls
The ls command ( lowercase L and lowercase S ) lists the contents of your current working directory.
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
Command Meaning
ls list files and directories
list all hidden files and
ls -a directories starting with dot
mkdir make a directory
cd directory change to named directory
cd change to home-directory
cd ~ change to home-directory
cd .. change to parent directory
display the path of the current
pwd directory
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc
Contd.
Command Meaning
cp file1 file2 copy file1 and call it file2
mv file1 file2 move or rename file1 to file2
rm file remove a file
rmdir directory remove a directory
display a file(cat file1 grep science science.txt
cat file file2>file3 grep Science science.txt
less file /o display a file a page at a time grep -i science science.txt
display the first few lines of a grep -i 'spinning top'
head -5 file file science.txt.
display the last few lines of a
tail file file Some of the other options of grep
search a file for keywords grep are:
grep 'keyword' file H file1(grep is case sensitive -v display those lines that do NOT
command) match
count number of -n precede each matching line with
lines/words/characters in file the line number
wc file wc -l science.txt -c print only the total count of
wc -w science.txt
matched lines
Accelerant Confidential
Contd.
Command Meaning
cat > list1
redirect standard output to pear
command > file a file
banana
append standard output to apple
command >> file a file ^D {this means press [Ctrl] and [d]
redirect standard input to stop}.
command < file from a file cat list1
Accelerant Confidential
Contd.
The * wildcard
The character * is called a wildcard, and will match against none or more character(s)
in a file (or directory) name. For example, in your unixstuffdirectory, type
ls list*
This will list all files in the current directory starting with list....
Try typing
ls *list1
This will list all files in the current directory ending with ....list
The ? wildcard
The character ? will match exactly one character.
So ?ouse will match files like house and mouse, but not grouse.
Try typing
ls list?
On-line Manuals
For example, to find out more about the wc (word count) command, type
man wc
Accelerant Confidential
Contd.
Access rights on files
r (or -), indicates read permission (or otherwise), that is, the presence or absence of
permission to read and copy the file
w (or -), indicates write permission (or otherwise), that is, the permission (or otherwise)
to change a file
x (or -), indicates execution permission (or otherwise), that is, the permission to
execute a file, where appropriate
Symbol Meaning chmod (changing a file mode
u user chmod go-rwx biglist
g group
chmod a+rw biglist
o other
chmod 777 file1
a all
r read
w write (and delete)
execute (and access
x
directory)
+ add permission
- take away
permission
Accelerant Confidential
Contd.
Processes and Jobs
ps
df
The df command reports on the space left on the file system. For example, to find out
how much space is left on the fileserver, type
df .
Accelerant Confidential
Contd.
du
The du command outputs the number of kilobyes used by each subdirectory. you want
to find out which directory has the most files. In your home-directory, type
du -s *
The -s flag will display only a summary (total size) and the * means all files and
directories.
gzip
This reduces the size of a file, thus freeing valuable disk space. For example, type
ls -l science.txt
and note the size of the file using ls -l . Then to compress science.txt, type
gzip science.txt
This will compress the file and place it in a file called science.txt.gz
To see the change in size, type ls -l again.
To expand the file, use the gunzip command.
gunzip science.txt.gz
zcat
zcat will read gzipped files without needing to uncompress them first.
zcat science.txt.gz
If the text scrolls too fast for you, pipe the output though less .
zcat science.txt.gz | less
Accelerant Confidential
UNIX Emulator
Download Mobaxterm – an UNIX emulator to practice UNIX
commands on your windows OS, from the following URL :
http://mobaxterm.mobatek.net/download.html
Accelerant Confidential
Please do not copy or redistribute without written consent of Accelerant Software, Inc