t utorial of u nix c ommand & shell script s 5027 professor: dr. shu-ching chen ta: samira...
TRANSCRIPT
![Page 1: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/1.jpg)
TUTORIAL OFUNIX COMMAND & SHELL SCRIPTS 5027
Professor: Dr. Shu-Ching Chen
TA: Samira Pouyanfar
Spring 2015
![Page 2: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/2.jpg)
2
OUTLINE
Log in Unix Basic Commands Shell script
![Page 3: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/3.jpg)
3
OUTLINE
Log in Unix Basic Commands Shell script
![Page 4: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/4.jpg)
4
HOW TO LOG IN
Download putty from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
![Page 5: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/5.jpg)
5
CONNECT TO THE SERVER
The host is margay.cs.fiu.edu
1
2
3
4
![Page 6: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/6.jpg)
6
LOG IN / ACCOUNT INFORMATION
Account information Login as : Your FIU username Password : Your first initial + PantherID + Your last initial
For exmaple, Steven Jackson with PID 1234567
should have password s1234567j
![Page 7: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/7.jpg)
7
LOG IN IN MAC SYSTEMS
Use the existing ssh tool in your mac called "Terminal" by following the steps: - Search for "Terminal" from spotlight, e.g., located on the
upper right corner of your screen - Open Terminal - Connect to the server margay.cs.fiu.edu using following
commands
replace hha001 with your fiu account
- Type your password - Now, you are connected.
![Page 8: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/8.jpg)
8
LOG IN IN MAC SYSTEMS
![Page 9: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/9.jpg)
9
OUTLINE
Log in Unix Basic Commands Shell script
![Page 10: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/10.jpg)
10
COMMANDS ABOUT FILES (1)
ls : list the contents of your current directory. Format Options
-a : list all the files include the hidden ones -l : list not only the files name but also the related info -t : list the contents by modified date
ls [option] [directory][file]
![Page 11: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/11.jpg)
11
COMMANDS ABOUT FILES (2)
File permission
Field1 : A set of ten permission flags Field2 : link count Field3 : owner of the file Field4 : associated group of the file Field5 : size Field 6-8 : Last modification date Field9 : file name
![Page 12: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/12.jpg)
12
COMMANDS ABOUT FILES (3)
chmod : change the permission flags of the files Format
Example chmod g+w myfile chmod g-rw myfile chmod u=rw go= myfile chmod –R g+rw myfile
chmod [option] [types][+/-][types of permission] filename
![Page 13: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/13.jpg)
13
COMMANDS ABOUT FILES (4)
pwd : print out the current working directory cd : change directory
cd . (.) means the current directory C (..) means the parent of current
directory Cd cd with no argument will return you to
your home directory
cd .
cd ..
cd
![Page 14: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/14.jpg)
14
COMMANDS ABOUT FILES (5)
cp : copy files Format Options
-i : It can be used to avoid overwriting the original file -r : Copy the folder and all the files and subfolders
under it.
mv : move a file from one place to another or rename a file.
Format
cp [option] File1 File2
mv File1 File2
![Page 15: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/15.jpg)
15
COMMANDS ABOUT FILES (6)
mkdir : making directory Format
rm : remove files or directories Format Option
-i : ask before actually delete -r : delete the folders and all the files and subfolders
under it
mkdir Directory_name
rm [option] file1 file2 file3…
![Page 16: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/16.jpg)
16
COMMANDS ABOUT FILES (7)
test : A command in Unix that evaluates conditional expressions. Format or The functions will return true if the object exist or the
condition specified is true. File functions
-d Filename : Filename is a directory -s Filename : Filename has a size greater than 0 -f Filename : Filename is a regular file
test expression [ expression ]
![Page 17: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/17.jpg)
17
COMMANDS ABOUT FILE’S CONTENTS (1)
cat : display the contents of a file on the screen Format
head : display the first ten lines of a file to the screen Format
tail : display the last ten lines of a file to the screen Format
cat file1
head –n file1
tail –n file1
![Page 18: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/18.jpg)
18
![Page 19: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/19.jpg)
19
COMMANDS ABOUT FILE’S CONTENTS (2)
wc : word count Format Options
-w : find out how many words the file has -l : find out how many lines the file has
wc [options] file
![Page 20: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/20.jpg)
20
COMMANDS ABOUT FILE’S CONTENTS (3)
grep : It searches files for the specified words or patterns.
Format: Options:
-c : Display the number of columns which satisfied the pattern.
-i : Ignore case distinctions in both the PATTERN and the input files.
-v : Invert the sense of matching, to select non-matching lines.
grep [options] [pattern] file
![Page 21: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/21.jpg)
21
Pipe : It cause the execution of multiple processes from one single line
A | B | C
![Page 22: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/22.jpg)
22
COMMANDS ABOUT FILE’S CONTENTS (4)
Redirection > and >> can be used on the output of
most commands to direct their output to a file. Examples
![Page 23: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/23.jpg)
23
COMMANDS ABOUT TEXT PROCESSING (1)
sort : sort lines of a text file or files Default : sort without any option will sort the file
alphabetically Format
uniq : remove duplicate adjacent lines from sorted file.
sort [option] file
![Page 24: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/24.jpg)
24
![Page 25: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/25.jpg)
25
COMMANDS ABOUT TEXT PROCESSING (2)
sed: One ultimate stream editor Detail Tutorial :
http://www.grymoire.com/Unix/Sed.html Important function -> Substitution Format : sed 's/term1/term2/g‘ filename
![Page 26: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/26.jpg)
26
COMMANDS ABOUT TEXT PROCESSING (3)
cut : extract sections from each line of a file. Format Option
-c : character -f : field -d “:” : delimiter (default is a tab)
Range N-M N- -M
cut [options] [range] filename
![Page 27: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/27.jpg)
27
![Page 28: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/28.jpg)
28
OUTLINE
Log in Unix Basic Commands Shell script
![Page 29: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/29.jpg)
29
SHELL SCRIPT INTRO (1)
Scripts are collections of commands that are stored in a file.
Detail Tutorial http://www.freeos.com/guides/lsst/
Basic Vi commands vim filename i : switch to the editing(insert) mode Esc +:q! Leave the vim program without saving
the file Esc +:w Save the file Esc +:wq Save the file and leave the vim program
![Page 30: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/30.jpg)
30
SHELL SCRIPT INTRO (2)
First shell script
Note that to make a file executable, you must set the eXecutable bit, and for a shell script, the Readable bit must also be set.
![Page 31: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/31.jpg)
31
SHELL SCRIPT INTRO (3)
Variable
![Page 32: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/32.jpg)
32
SHELL SCRIPT INTRO (4)
IF LOOP
![Page 33: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/33.jpg)
33
SHELL SCRIPT INTRO (5)
For Loop
![Page 34: T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015](https://reader030.vdocuments.site/reader030/viewer/2022032704/56649d6e5503460f94a4f425/html5/thumbnails/34.jpg)
34
SHELL SCRIPT INTRO (6)
Useful concept $( commands)