Download presentation
Presentation is loading. Please wait.
Published byHilary Wiggins Modified over 9 years ago
1
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015
2
O UTLINE Log in Unix Basic Commands Shell script 2
3
O UTLINE Log in Unix Basic Commands Shell script 3
4
H OW TO LOG IN Download putty from http://www.chiark.greenend.org.uk/~sgtatham/putty/ download.html http://www.chiark.greenend.org.uk/~sgtatham/putty/ download.html 4
5
C ONNECT TO THE SERVER The host is margay.cs.fiu.edu 1 2 3 4 5
6
L OG IN / A CCOUNT 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 6
7
L OG IN IN M AC 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 ssh hha001@margay.cs.fiu.edu replace hha001 with your fiu account - Type your password - Now, you are connected. 7
8
L OG IN IN M AC SYSTEMS 8
9
O UTLINE Log in Unix Basic Commands Shell script 9
10
C OMMANDS ABOUT F ILES (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] 10
11
C OMMANDS ABOUT F ILES (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 11
12
C OMMANDS ABOUT F ILES (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 12
13
C OMMANDS ABOUT F ILES (4) pwd : print out the current working directory cd : change directory cd. (.) means the current directory C(..) means the parent of current directory Cdcd with no argument will return you to your home directory cd. cd.. cd 13
14
C OMMANDS ABOUT F ILES (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 14
15
C OMMANDS ABOUT F ILES (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… 15
16
C OMMANDS ABOUT F ILES (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 ] 16
17
C OMMANDS ABOUT F ILE ’ 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 17
18
18
19
C OMMANDS ABOUT F ILE ’ 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 19
20
C OMMANDS ABOUT F ILE ’ 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 20
21
Pipe : It cause the execution of multiple processes from one single line A | B | C 21
22
C OMMANDS ABOUT F ILE ’ S CONTENTS (4) Redirection > and >> can be used on the output of most commands to direct their output to a file. Examples 22
23
C OMMANDS ABOUT T EXT 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 23
24
24
25
C OMMANDS ABOUT T EXT PROCESSING (2) sed: One ultimate stream editor Detail Tutorial : http://www.grymoire.com/Unix/Sed.html http://www.grymoire.com/Unix/Sed.html Important function -> Substitution Format : sed 's/term1/term2/g‘ filename 25
26
C OMMANDS ABOUT T EXT 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 26
27
27
28
O UTLINE Log in Unix Basic Commands Shell script 28
29
S HELL SCRIPT INTRO (1) Scripts are collections of commands that are stored in a file. Detail Tutorial http://www.freeos.com/guides/lsst/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 29
30
S HELL 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. 30
31
S HELL SCRIPT INTRO (3) Variable 31
32
S HELL SCRIPT INTRO (4) IF LOOP 32
33
S HELL SCRIPT INTRO (5) For Loop 33
34
S HELL S CRIPT I NTRO (6) Useful concept $( commands) 34
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.