Upload
marcos-luis-soares
View
238
Download
0
Embed Size (px)
Citation preview
Introduction to UNIX
Unix File SystemStores FilesText, Programs, Images, etc.Made up of Many FilesUser, Unix System, Unix Commands
Unix File System
Unix File SystemHome DirectoryPersonal Directory to store filesUsually the Directory Name = login IDCurrent Directory after successful loginHome directories for: rdefe, jsmith and djones
Unix File SystemWhat Can You Do?Create New Files & DirectoriesOrganize FilesLocate Files Based on a Directory StructureChange to a New Directory
Unix File SystemFile & Directory Naming GuidelinesDont Use Meta Characters/ \ ` * ; ? { } ( ) [ ] ~ ! $ < > | & # Do Usea-z A-Z0-9. _ -Remember Unix is Case Sensitive!
Unix File SystemFile & Directory Name Examplesfeb1998, 178987, my_data, my.data.newmbox, Mbox, mboX, MBOX, mBoxprog1..2 .profile
Unix Commandsls List Files & Directories
$ ls198Aaa.bb.cc.ddbindatefileetcmailmboxmbox.oldunix$
Unix Commandsls -p-p Show Directories$ ls -p198Aaa.bb.cc.ddbin/datefileetc/mail/mboxmbox.oldunix/$
Unix Commandsls [directory1] [directory2] ...List the contents of a directory$ ls unixawk.dataawk.prgbgraphcpyhomework2homework3unix2test$$ ls -p198Aaa.bb.cc.ddbin/datefileetc/mail/mboxmbox.oldunix/$
Unix Commandsls -s-s Show File Size in BlocksBlock Sizes512 bytes1024 bytes2048 bytes$ ls -stotal 19 1 198 1 A 1 aa.bb.cc.dd 1 bin 1 datefile 1 etc 1 mail 2 mbox 1 unix
Unix Commandsls -l-l Long Listing
$ ls -ltotal 19-rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 198-rw-r--r-- 1 rdefe unix 62 Sep 12 21:47 Adrwxr-xr-x 2 rdefe unix 96 Sep 4 20:58 bindrwxr-xr-x 3 rdefe unix 80 Aug 29 20:54 dbdrwxr-xr-x 2 rdefe unix 64 Aug 29 20:54 etcdrwxr-xr-x 2 rdefe unix 32 Sep 2 1992 mail-rw------- 1 rdefe unix 984 Sep 12 21:44 mboxdrwxr-xr-x 2 rdefe unix 144 Aug 29 20:54 unix$
Unix Commandsls -a-a List All Files
$ ls -a....profile.sh_history198Abindatefiledbetcmboxunix$Include Files That Begin with a .Files that begin with a . are usually configuration files
Unix Commandsls -r-r Reverse Sortls -R-R List Contents of Subdirectories
$ ls -runixmboxmailetcdbdatefilebinA198$ List files in each subdirectory. Subdirectories with Subdirectories will also be listedand so on...
Unix Commandsls -l -torls -lt-t Sort On Modification Time
$ ls -lttotal 19-rw-r--r-- 1 rdefe unix 62 Sep 12 21:47 A-rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 198-rw------- 1 rdefe unix 984 Sep 12 21:44 mboxdrwxr-xr-x 2 rdefe unix 96 Sep 4 20:58 bindrwxr-xr-x 2 rdefe unix 64 Aug 29 20:54 etcdrwxr-xr-x 2 rdefe unix 144 Aug 29 20:54 unixdrwxr-xr-x 3 rdefe unix 80 Aug 29 20:54 dbdrwxr-xr-x 2 rdefe unix 32 Sep 2 1992 mail$
Unix Commandsls -l -t -r or ls -ltr-tr Reverse Sort On Modification Time
$ ls -ltrtotal 19drwxr-xr-x 2 rdefe unix 32 Sep 2 1992 maildrwxr-xr-x 3 rdefe unix 80 Aug 29 20:54 dbdrwxr-xr-x 2 rdefe unix 144 Aug 29 20:54 unixdrwxr-xr-x 2 rdefe unix 64 Aug 29 20:54 etcdrwxr-xr-x 2 rdefe unix 96 Sep 4 20:58 bin-rw------- 1 rdefe unix 984 Sep 12 21:44 mbox-rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 198-rw-r--r-- 1 rdefe unix 62 Sep 12 21:47 A$
Unix Commandsls -[ltrRa] [Filename1] [Filename2] UnixCommand Options Arguments$ ls -lt unix$
Unix Commandscat [Filename1] [Filename2] Concatenate FilesDisplay Files to the ScreenCtrl-s Pause ScreenCtrl-q Unpause Screen
$ cat sample.fileThis is a sample file that i'll use to demo how the pr command is used.The pr command is useful in formattingvarious types of text files.$
Unix Commandsmore [Filename1] [Filename2] Display Files to the screen one page at a time$ more largefileThis is a sample file that i'll use to demo how the pr command is used.The pr command is useful in formattingvarious types of text files.--More--(16%)Spacebar (next page)b (previous page)Enter Key (next line) q (Quit & return to unix)/string (search for string):n (next file):p (previous file)
Unix Commandspr [Filename1] [Filename2] Format & Display Files to the Screen
$ pr sample.file
98-05-22 23:07 sample.file Page 1
This is a sample file that i'll use to demo how the pr command is used.The pr command is useful in formattingvarious types of text files.$
Unix Commandspr -[dn] [Filename1] [Filename2] -d Double Space Output-n Number Lines$ pr -d sample.file
98-05-22 23:07 sample.file Page 1
This is a sample file that i'll use to demo how
the pr command is used.
The pr command is useful in formatting
various types of text files.$$ pr -n sample.file
98-05-22 23:07 sample.file Page 1
1 This is a sample file that i'll use to demo how the 2 pr command is used. 3 The pr command is useful in formatting 4 various types of text files.$
Unix Commandslpr [Filename1] [Filename2] Send Files to a Unix PrinterNo Formatting (page numbers, etc.)
$ lpr prog1 mbox$
Unix RedirectionOutput Normally Displayed to the Screen is Redirected and Becomes the Input to Another Command$ pr prog1 | lpr$
Unix RedirectionThe Output of One Command can be used as the Input to Another
Command | CommandCommand that generates screen outputCommand that requires input$ pr prog1 | lpr$
Unix RedirectionCommand | Command | Command ...$ ls | pr | lpr$Directory Listing Formatted Using pr, Printed on Paper
Unix RedirectionOutput Normally Displayed to the Screen Can Be Redirected to a File$ pr prog1 > prog1.pr$The file prog1.pr contains the output of the pr commandNote: Nothing is displayed to the screen
Unix RedirectionRedirecting Output The Output of Command can be saved to a File
Command > FileCommand that generates screen outputFile used to capture (save) screen output$ pr prog1 > prog1.pr$Caution: Output File will be erased if it already exists.
Unix RedirectionRedirecting InputA Command Requiring Input Can Receive its Input From a File$ mail rdefe < mesg$
Unix RedirectionRedirecting Input
Command < FileCommand that requires inputFile used to provide input (instead of typing it!)$ mail rdefe < mesg$
Redirection Examples
Redirection Examples
Unix Commandsrm [Filename1] [Filename2] remove files
$ rm prog1 mbox$Caution Unix Assumes You Know What Your DoingBe Sure You Know What Your DeletingNo Undelete!$ rm *$
Unix Commandsvi [Filename]Full Screen, Visual EditorChanges Displayed As They Are MadeEdits A Copy of the FileChanges Must Be Saved
$ vi mesg emacshttp://www.gnu.org/software/emacs/emacs.html
Unix CommandsVi ModesCommand ModeStart in command modeEvery Key Performs an Editing CommandInsert ModePerform Text Entry/InputCommand ModeInsert ModeInsert Mode CommandESC Key
Sample vi Edit SessionStart in Command ModePress a key for Append After Cursor CommandEnter text (Input Mode)Press ESC key (Command Mode)Press :wq followed by Enter key to Save & Exit
Wnewtextelcome to UNIX
This is an example ofa text file in vi~~:wq$
Cursor PositioningMoving the Cursor in Command ModewForward One Wordb Backward One WordCntrl-dScroll DownCntrl-uScroll UpEnterDown One Line GGo To Last Line5GGo To Line 5KeyCommand
Text Input Modevi Text Input Mode Commands
Deleting TextProceed Any Command with a Number to multiply effect4xDelete 4 chars5ddDelete 5 lines3dwDelete 3 words
Undo ChangesWelcome to UNIX
This is an example ofa text file in vi~~Welcome to UNIX
This is an example ofa text file in vi~~
Saving Your ChangesCommand ModeZZSave & Exit vi:wqSave & Exit vi:w dataSave to a file data:q!Quit Without Saving Changes
Vi Referencehttp://www.eng.hawaii.edu/Tutor/vi.html
Other Goodies.../stringForward Search for `string`?stringBackward Search for `string`nRepeat SearchNRepeat Search in reverse directionCtrl-GDisplay Current Location in FileJJoin two lines together
http://www.thomer.com/thomer/vi/vi.html