TUTORIAL OF UNIX COMMAND SHELL SCRIPTS 5027 Professor











![COMMANDS ABOUT FILES (5) cp : copy files � Format cp [option] File 1 COMMANDS ABOUT FILES (5) cp : copy files � Format cp [option] File 1](https://slidetodoc.com/presentation_image_h2/085f5d1fa7542bc06f15e018fc2d2343/image-12.jpg)




![COMMANDS ABOUT FILE’S CONTENTS (2) wc : word count � Format wc [options] file COMMANDS ABOUT FILE’S CONTENTS (2) wc : word count � Format wc [options] file](https://slidetodoc.com/presentation_image_h2/085f5d1fa7542bc06f15e018fc2d2343/image-17.jpg)















- Slides: 32

TUTORIAL OF UNIX COMMAND & SHELL SCRIPTS 5027 Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha

OUTLINE Log in Unix Basic Commands Shell script

OUTLINE Log in Unix Basic Commands Shell script

HOW TO LOG IN Download putty from http: //www. chiark. greenend. org. uk/~sgtatham/putty/dow nload. html

CONNECT TO THE SERVER The host is margay. cs. fiu. edu 1 2 3 4

LOG IN / ACCOUNT INFORMATION Account information Login as : Your FIU username Password : Your first initial + Panther. ID + Your last initial For exmaple, Steven Jackson with PID 1234567 should have password s 1234567 j

OUTLINE Log in Unix Basic Commands Shell script

COMMANDS ABOUT FILES (1) ls : list the contents of your current directory. � Format ls [option] [directory][file] � 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

COMMANDS ABOUT FILES (2) File permission Field 1 : A set of ten permission flags Field 2 : link count Field 3 : owner of the file Field 4 : associated group of the file Field 5 : size Field 6 -8 : Last modification date Field 9 : file name

COMMANDS ABOUT FILES (3) chmod : change the permission flags of the files � Format chmod [option] [types][+/-][types of permission] filename � Example chmod g+w myfile chmod g-rw myfile chmod u=rw go= myfile chmod –R g+rw myfile

COMMANDS ABOUT FILES (4) pwd : print out the current working directory cd : change directory cd. � cd cd. . �C � Cd cd (. ) means the current directory (. . ) means the parent of current directory cd with no argument will return you to your home directory
![COMMANDS ABOUT FILES 5 cp copy files Format cp option File 1 COMMANDS ABOUT FILES (5) cp : copy files � Format cp [option] File 1](https://slidetodoc.com/presentation_image_h2/085f5d1fa7542bc06f15e018fc2d2343/image-12.jpg)
COMMANDS ABOUT FILES (5) cp : copy files � Format cp [option] File 1 File 2 � 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 mv File 1 File 2

COMMANDS ABOUT FILES (6) mkdir : making directory � Format mkdir Directory_name rm : remove files or directories � Format rm [option] file 1 file 2 file 3… � Option -i : ask before actually delete -r : delete the folders and all the files and subfolders under it

COMMANDS ABOUT FILES (7) test : A command in Unix that evaluates conditional expressions. [ expression ] or � The functions will return true if the object exist or the condition specified is true. � File functions � Format test expression -d Filename : Filename is a directory -s Filename : Filename has a size greater than 0 -f Filename : Filename is a regular file

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 cat file 1 head –n file 1 tail : display the last ten lines of a file to the screen � Format tail –n file 1

![COMMANDS ABOUT FILES CONTENTS 2 wc word count Format wc options file COMMANDS ABOUT FILE’S CONTENTS (2) wc : word count � Format wc [options] file](https://slidetodoc.com/presentation_image_h2/085f5d1fa7542bc06f15e018fc2d2343/image-17.jpg)
COMMANDS ABOUT FILE’S CONTENTS (2) wc : word count � Format wc [options] file � Options -w : find out how many words the file has -l : find out how many lines the file has

COMMANDS ABOUT FILE’S CONTENTS (3) grep : It searches files for the specified words or patterns. � Format: grep [options] [pattern] file � 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.

Pipe : It cause the execution of multiple processes from one single line A|B|C

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

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 sort [option] file uniq : remove duplicate adjacent lines from sorted file.


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/term 1/term 2/g‘ filename

COMMANDS ABOUT TEXT PROCESSING (3) cut : extract sections from each line of a file. � Format cut [options] [range] filename � Option -c : character -f : field -d “: ” : delimiter (default is a tab) � Range N-M N -M


OUTLINE Log in Unix Basic Commands Shell script

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

SHELL SCRIPT INTRO (2) First shell script Note that to make a file executable, you must set the e. Xecutable bit, and for a shell script, the Readable bit must also be set.

SHELL SCRIPT INTRO (3) Variable

SHELL SCRIPT INTRO (4) IF LOOP

SHELL SCRIPT INTRO (5) For Loop

SHELL SCRIPT INTRO (6) Useful concept $( commands)